【问题标题】:Improve Lucene search speed with a hitcollector使用 hitcollector 提高 Lucene 搜索速度
【发布时间】:2013-04-03 11:47:54
【问题描述】:

是否可以通过使用 Lucene 的 Hitcollector 来减少搜索时间?如果可以,在以下情况下如何正确实施?

// search login here ie. 
// this is the search method
// random query
if (!string.IsNullOrEmpty(vendor))
{
   bQuery.Add(qbVendor.Parse(vendor.ToLower()), BooleanClause.Occur.MUST);
}

bQuery.Add(qbWebsite.Parse(website.ToLower()), BooleanClause.Occur.MUST);
TopDocs hits = this.ProductIndexSearcher.Search(bQuery, null, 1000)
return hits.scoreDocs;

这部分将是函数调用:

ScoreDoc[] docs = null;
docs = s.KeywordSearch(keyword, category, Webshop.Context.InSiteWebshopId, null, null).ToList(), 1000

foreach (ScoreDoc d in docs.Take(maxResult))
{                                
   Document doc = this.ProductIndexSearcher.Doc(d.doc);
}

据我了解,不建议使用 Searcher.Doc 从搜索结果中获取文档,而是使用 hitcollector。我试图让一个hitcollector加入,但结果很混乱。任何帮助将不胜感激!

编辑: 澄清我担心的问题:

为了获得良好的搜索性能,此方法的实现不应 调用 Searcher.doc(int) 或 每个文档上的 org.apache.lucene.index.IndexReader.document(int) 遇到的号码。这样做会降低搜索速度 数量级或更大。

参考:http://grepcode.com/file/repo1.maven.org/maven2/org.apache.lucene/lucene-core/2.9.1/org/apache/lucene/search/HitCollector.java

所以我只是想知道添加一个 hitcollector 是否会给我们带来一些额外的性能。如果在第一个答案中指定调用 Searcher.Search(params) 时不需要使用 HitCollector,我可以。你能确认一下吗?

【问题讨论】:

    标签: performance lucene lucene.net


    【解决方案1】:

    HitCollector 在 2.9 中已弃用,并从 3.0 中完全删除。不要使用它。

    如果你需要它,你应该实现你自己的Collector。如果您想获得搜索的原始结果,这通常很有用,自定义评分、过滤等需要这些结果。

    不清楚您在这里要求什么,但是您发布的代码并没有做任何花哨的事情,而且您似乎想要“前 n 个结果”。

    因此您应该使用 TopDocsCollector,它会被 Searcher.Search(Query,int) 方法自动使用。

    我还建议您阅读Searchable.Search(Weight weight, Filter filter, Collector collector) 方法中的文档:

    低级搜索 API。

    为每个文档调用 Collector.collect(int)。基于收集器 不鼓励访问远程索引。

    应用程序仅在需要所有匹配项时才应使用它 文件。高级搜索 API (Searcher.search(Query,int)) 是 通常效率更高,因为它会跳过非高分命中。

    【讨论】:

    • 非常感谢您的回答。据我了解,我不必使用 hitcollector,因为在检索文档后我确实没有做任何花哨的事情。我认为使用 HitCollector 可以提高整体收集 scoredocs 的性能。如果这个 Searcher.Search 已经在使用 hitcollector,它似乎没问题。
    猜你喜欢
    • 1970-01-01
    • 2016-03-12
    • 2020-12-24
    • 2011-07-29
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    相关资源
    最近更新 更多