问题描述
我正在使用以下代码在 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
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.Searcher.search
方法将接受 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或整数
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 String
s, Float
s or Integer
s.
Lucene in Action 涵盖了所有细节,以及按多个字段排序等.
Lucene in Action covers all of the details, as well as sorting by multiple fields and so on.
这篇关于如何使用 HitCollector 按字段值对 Lucene 结果进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!