吃了个饭回来,觉得Lucene有些知识点用法还没讲到,在这里补充一下:
一.Lucene的增删查改
/**
* 增删查改
*
* @throws Exception
*/
public static void insert() throws Exception {
String text5 = "hello,goodbye,man,woman";
Date date1 = new Date();
analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
directory = FSDirectory.open(new File(INDEX_DIR));
IndexWriterConfig config = new IndexWriterConfig(
Version.LUCENE_CURRENT, analyzer);
indexWriter = new IndexWriter(directory, config);
<span style="white-space:pre"> </span>
//增加索引
/*Document doc1 = new Document();
doc1.add(new TextField("filename", "text5", Store.YES));
doc1.add(new TextField("content", text5, Store.YES));
indexWriter.addDocument(doc1);
indexWriter.commit();
indexWriter.close();
<span style="white-space:pre"> </span>*/
<span style="white-space:pre"> </span>
//删除索引
<span style="white-space:pre"> </span>/*
<span style="white-space:pre"> indexWriter.deleteDocuments(new Term("filename",str));
indexWriter.close();</span>
<span style="white-space:pre"> </span>*/
<span style="white-space:pre"> </span>
//更新索引
Date date2 = new Date();
System.out.println("增加索引耗时:" + (date2.getTime() - date1.getTime()) + "ms\n");
} 二.Lucene评分机制
如图为公式,可以通过Document的setBoost方法来改变一下文档的boost因子进而修改分值。
本文详细介绍了Lucene中的文档增删查改操作,并通过实例代码展示了如何使用Lucene进行文档索引的创建与管理。此外,还探讨了Lucene的评分机制及如何通过调整文档的boost因子来影响评分。
&spm=1001.2101.3001.5002&articleId=44625001&d=1&t=3&u=d51609abfca3447a8a59e4e6bd9a7225)
5311

被折叠的 条评论
为什么被折叠?



