19 using Lucene.Net.Util;
21 namespace Lucene.Net.Search
41 internal Entry(
int slot,
int doc,
float score)
48 public override System.String ToString()
50 return "slot:" + slot +
" " + base.ToString();
61 private int oneReverseMul;
63 public OneComparatorFieldValueHitQueue(
SortField[] fields,
int size):base(fields)
65 if (fields.Length == 0)
67 throw new System.ArgumentException(
"Sort must contain at least one field");
72 oneReverseMul = field.reverse?- 1:1;
74 comparators[0] = comparator;
75 reverseMul[0] = oneReverseMul;
84 public override bool LessThan(
Entry hitA,
Entry hitB)
86 System.Diagnostics.Debug.Assert(hitA != hitB);
87 System.Diagnostics.Debug.Assert(hitA.slot != hitB.slot);
89 int c = oneReverseMul * comparator.Compare(hitA.slot, hitB.slot);
96 return hitA.Doc > hitB.Doc;
103 private sealed
class MultiComparatorsFieldValueHitQueue : FieldValueHitQueue
106 public MultiComparatorsFieldValueHitQueue(
SortField[] fields,
int size):base(fields)
109 int numComparators = comparators.Length;
110 for (
int i = 0; i < numComparators; ++i)
114 reverseMul[i] = field.reverse?- 1:1;
115 comparators[i] = field.GetComparator(size, i);
121 public override bool LessThan(
Entry hitA,
Entry hitB)
123 System.Diagnostics.Debug.Assert(hitA != hitB);
124 System.Diagnostics.Debug.Assert(hitA.slot != hitB.slot);
126 int numComparators = comparators.Length;
127 for (
int i = 0; i < numComparators; ++i)
129 int c = reverseMul[i] * comparators[i].Compare(hitA.slot, hitB.slot);
138 return hitA.Doc > hitB.Doc;
143 private FieldValueHitQueue(
SortField[] fields)
151 this.fields = fields;
152 int numComparators = fields.Length;
153 comparators =
new FieldComparator[numComparators];
154 reverseMul =
new int[numComparators];
172 if (fields.Length == 0)
174 throw new System.ArgumentException(
"Sort must contain at least one field");
177 if (fields.Length == 1)
179 return new OneComparatorFieldValueHitQueue(fields, size);
183 return new MultiComparatorsFieldValueHitQueue(fields, size);
192 internal virtual int[] GetReverseMul()
199 protected internal FieldComparator[] comparators;
200 protected internal int[] reverseMul;
202 public abstract override bool LessThan(
Entry a,
Entry b);
217 internal virtual FieldDoc FillFields(
Entry entry)
219 int n = comparators.Length;
220 System.IComparable[] fields =
new System.IComparable[n];
221 for (
int i = 0; i < n; ++i)
223 fields[i] = comparators[i][entry.slot];
226 return new FieldDoc(entry.Doc, entry.Score, fields);