小编rrs*_*rsk的帖子

通过lucene中的IndexReader或IndexSearcher打开目录

这两个代码有什么区别?基于性能导向和面向文档

直接使用目录 IndexSearcher

Analyzer anal = new StandardAnalyzer(Version.LUCENE_30);
QueryParser parser = new QueryParser(Version.LUCENE_30, "", anal);
Query query = parser.parse(queryStr);
Searcher searcher = new IndexSearcher(NIOFSDirectory.open(new File(indexDir)));
Run Code Online (Sandbox Code Playgroud)

使用目录IndexReader然后使用该阅读器打开搜索器

Analyzer anal = new StandardAnalyzer(Version.LUCENE_30);
QueryParser parser = new QueryParser(Version.LUCENE_30, "", anal);
Query query = parser.parse(queryStr);
IndexReader ir = IndexReader.open(NIOFSDirectory.open(new File(indexDir)), false);
IndexSearcher searcherNew = new IndexSearcher(ir);
Run Code Online (Sandbox Code Playgroud)

lucene performance

3
推荐指数
1
解决办法
3751
查看次数

在排序时解释lucene中的得分

在lucene索引中搜索时,我在topDocs.scoreDocs中为某些文档获取null值.请解释一下 topDocs.scoreDocs 中[]的值

SortField sortFieldObj = new SortField(sortField, SortField.STRING, sortOrder);
Sort sort = new Sort(sortFieldObj);
TopDocs topDocs = searcher.search(query, null, sizeNeeded, sort);
Document docNew = searcher.doc(topDocs.scoreDocs[i].doc);
System.out.println(topDocs.scoreDocs[i]);
Run Code Online (Sandbox Code Playgroud)

输出:

doc = 2得分= NaN [ null ]

doc = 44得分= NaN [ testString ]

sorting lucene search full-text-search scoring

1
推荐指数
1
解决办法
1956
查看次数