更快的方式从Lucene的查询得到不同的值 [英] Faster way to get distinct values from Lucene Query

查看:125
本文介绍了更快的方式从Lucene的查询得到不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我做的是这样的:

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的查询得到不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆