java 基于lucene 如何创建index【索引】
程序员文章站
2022-07-09 09:35:36
...
/**
* 基于lucene 如何创建index【索引】
* @param indexPath 索引文件路径
* @param analyzer 分词器
* @param list 文档对象集合
* @throws Exception
*/
public static void createIndex(String indexPath,Analyzer analyzer,List<Document> list) throws Exception{
Directory directory=FSDirectory.open(new File(indexPath));
// Analyzer analyzer=new StandardAnalyzer();
// Document document=new Document();
// document.add(new Field("name","chenxiaoyang", Field.Store.YES, Field.Index.ANALYZED));
// document.add(new Field("address","beijing", Field.Store.YES, Field.Index.ANALYZED));
// document.add(new Field("sex","man" ,Field.Store.YES, Field.Index.ANALYZED));
// document.add(new Field("introduce"," i am chenxuyuan",Field.Store.YES,Field.Index.ANALYZED));
IndexWriter indexWriter=new IndexWriter(directory,analyzer, IndexWriter.MaxFieldLength.LIMITED);
for (Document document:list){
indexWriter.addDocument(document);
}
indexWriter.close();
}
上一篇: 索引index
下一篇: Lucene查询结果高亮