从 Lucene Query 获取不同值的更快方法

Faster way to get distinct values from Lucene Query(从 Lucene Query 获取不同值的更快方法)
本文介绍了从 Lucene Query 获取不同值的更快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我喜欢这样:

IndexSearcher searcher = new IndexSearcher(lucenePath);
Hits hits = searcher.Search(query);
Document doc;
List<string> companyNames = new List<string>();

for (int i = 0; i < hits.Length(); i++)
{
    doc = hits.Doc(i);
    companyNames.Add(doc.Get("companyName"));
}
searcher.Close();

companyNames = companyNames.Distinct<string>().Skip(offSet ?? 0).ToList();
return companyNames.Take(count??companyNames.Count()).ToList();

如您所见,我首先收集所有字段(数千个)然后区分它们,可能会跳过一些并取出一些.

As you can see, I first collect ALL the fields (several thousands) and then distinct them, possibly skip some and take some out.

我觉得应该有更好的方法来做到这一点.

I feel like there should be a better way to do this.

推荐答案

老实说,我不确定是否存在,因为 Lucene 不提供独特"的功能.我相信使用 SOLR 您可以使用构面搜索来实现这一点,但是如果您想在 Lucene 中实现这一点,则必须自己编写某种构面功能.所以只要你没有遇到任何性能问题,你应该没问题.

I'm not sure there is, honestly, as Lucene doesn't provide 'distinct' functionality. I believe with SOLR you can use a facet search to achieve this, but if you want this in Lucene, you'd have to write some sort of facet functionality yourself. So as long as you don't run into any performance issues, you should be ok this way.

这篇关于从 Lucene Query 获取不同值的更快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)