是否有可能在使用自定义收集器时对Lucene结果进行排序,或者我必须在收集器对象中自己实现该功能?我找不到IndexSearcher的过载。搜索允许我传入我自己的收集器对象和排序字段。
Lucene。净,v2.9
您必须自己实现排序。但Lucene。Net有一个抽象类PriorityQueue
,可以在自定义收集器中使用(它在Lucene内部使用)。(而不是收集所有结果然后对它们应用排序))
public class MyQueue : Lucene.Net.Util.PriorityQueue<int>
{
public MyQueue(int MaxSize) : base()
{
Initialize(MaxSize);
}
public override bool LessThan(int a, int b)
{
return a < b;
}
}
int queueSize = 3;
MyQueue pq = new MyQueue(queueSize);
pq.InsertWithOverflow(1);
pq.InsertWithOverflow(9);
pq.InsertWithOverflow(8);
pq.InsertWithOverflow(3);
pq.InsertWithOverflow(5);
int i1 = pq.Pop();
int i2 = pq.Pop();
int i3 = pq.Pop();