WriteDoucment public class WriterDocument {@SuppressWarnings("resource")public static void main(String[] args) throws Exception {//创建文档对象Document document = new Document();document.add(new LongField("id",1L,Store.YES));document.
public class WriterDocument { @SuppressWarnings("resource") public static void main(String[] args) throws Exception { //创建文档对象 Document document = new Document(); document.add(new LongField("id",1L,Store.YES)); document.add(new TextField("title", "以客户为中心,以奋斗者为本,长期艰苦奋斗", Store.YES)); document.add(new StringField("sellpoint", "huawei", Store.YES)); //建立目录 FSDirectory directory = FSDirectory.open(new File("index")); //分词器,使用标准分词器 // Analyzer analyzer = new StandardAnalyzer(); Analyzer analyzer = new IKAnalyzer(); //定义索引配置 IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_4_10_2, analyzer); //建立写索引库对象 IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig); //添加文档 indexWriter.addDocument(document); //提交 indexWriter.commit(); //关闭 indexWriter.close(); System.out.println("ok"); } }