如何使用HitCollector按字段值对Lucene结果进行排序? [英] How do I sort Lucene results by field value using a HitCollector?

查看:123
本文介绍了如何使用HitCollector按字段值对Lucene结果进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在Lucene.Net中执行查询

I'm using the following code to execute a query in Lucene.Net

var collector = new GroupingHitCollector(searcher.GetIndexReader());
searcher.Search(myQuery, collector);
resultsCount = collector.Hits.Count;

如何根据字段对这些搜索结果进行排序?

How do I sort these search results based on a field?

感谢您的答案.我曾尝试使用TopFieldDocCollector,但是当我将5000作为numHits参数值传递时,出现错误消息"value is too small or too large".请提出一个有效的值来传递.

Thanks for your answer. I had tried using TopFieldDocCollector but I got an error saying, "value is too small or too large" when i passed 5000 as numHits argument value. Please suggest a valid value to pass.

推荐答案

search.Sort 参数,可以将其构造如下:

The search.Searcher.search method will accept a search.Sort parameter, which can be constructed as simply as:

new Sort("my_sort_field")

但是,对可以对哪些字段进行排序存在一些限制-需要对其进行索引但不对它们进行标记化,并且这些值可以转换为String s,Float s或Integer s.

However, there are some limitations on which fields can be sorted on - they need to be indexed but not tokenized, and the values convertible to Strings, Floats or Integers.

Lucene in Action 涵盖了所有详细信息,以及按多个字段进行排序等

Lucene in Action covers all of the details, as well as sorting by multiple fields and so on.

这篇关于如何使用HitCollector按字段值对Lucene结果进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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