19 using Lucene.Net.Support;
29 namespace Lucene.Net.Search
96 public abstract int Compare(
int slot1,
int slot2);
106 public abstract void SetBottom(
int slot);
126 public abstract int CompareBottom(
int doc);
138 public abstract void Copy(
int slot,
int doc);
149 public abstract void SetNextReader(
IndexReader reader,
int docBase);
158 public virtual void SetScorer(
Scorer scorer)
171 public abstract IComparable
this[
int slot] {
get; }
178 private sbyte[] values;
179 private sbyte[] currentReaderValues;
180 private System.String field;
182 private sbyte bottom;
184 internal ByteComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
186 values =
new sbyte[numHits];
191 public override int Compare(
int slot1,
int slot2)
193 return values[slot1] - values[slot2];
196 public override int CompareBottom(
int doc)
198 return bottom - currentReaderValues[doc];
201 public override void Copy(
int slot,
int doc)
203 values[slot] = currentReaderValues[doc];
206 public override void SetNextReader(
IndexReader reader,
int docBase)
208 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetBytes(reader, field, parser);
211 public override void SetBottom(
int bottom)
213 this.bottom = values[bottom];
216 public override IComparable
this[
int slot]
218 get {
return (sbyte) values[slot]; }
225 private int[] docIDs;
231 docIDs =
new int[numHits];
234 public override int Compare(
int slot1,
int slot2)
237 return docIDs[slot1] - docIDs[slot2];
240 public override int CompareBottom(
int doc)
243 return bottom - (docBase + doc);
246 public override void Copy(
int slot,
int doc)
248 docIDs[slot] = docBase + doc;
251 public override void SetNextReader(
IndexReader reader,
int docBase)
256 this.docBase = docBase;
259 public override void SetBottom(
int bottom)
261 this.bottom = docIDs[bottom];
264 public override IComparable
this[
int slot]
266 get {
return (System.Int32) docIDs[slot]; }
275 private double[] values;
276 private double[] currentReaderValues;
277 private System.String field;
279 private double bottom;
281 internal DoubleComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
283 values =
new double[numHits];
288 public override int Compare(
int slot1,
int slot2)
290 double v1 = values[slot1];
291 double v2 = values[slot2];
306 public override int CompareBottom(
int doc)
308 double v2 = currentReaderValues[doc];
313 else if (bottom < v2)
323 public override void Copy(
int slot,
int doc)
325 values[slot] = currentReaderValues[doc];
328 public override void SetNextReader(
IndexReader reader,
int docBase)
330 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetDoubles(reader, field, parser);
333 public override void SetBottom(
int bottom)
335 this.bottom = values[bottom];
338 public override IComparable
this[
int slot]
340 get {
return (
double) values[slot]; }
349 private float[] values;
350 private float[] currentReaderValues;
351 private System.String field;
353 private float bottom;
355 internal FloatComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
357 values =
new float[numHits];
362 public override int Compare(
int slot1,
int slot2)
366 float v1 = values[slot1];
367 float v2 = values[slot2];
382 public override int CompareBottom(
int doc)
386 float v2 = currentReaderValues[doc];
391 else if (bottom < v2)
401 public override void Copy(
int slot,
int doc)
403 values[slot] = currentReaderValues[doc];
406 public override void SetNextReader(
IndexReader reader,
int docBase)
408 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetFloats(reader, field, parser);
411 public override void SetBottom(
int bottom)
413 this.bottom = values[bottom];
416 public override IComparable
this[
int slot]
418 get {
return (
float) values[slot]; }
427 private int[] values;
428 private int[] currentReaderValues;
429 private System.String field;
433 internal IntComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
435 values =
new int[numHits];
440 public override int Compare(
int slot1,
int slot2)
446 int v1 = values[slot1];
447 int v2 = values[slot2];
462 public override int CompareBottom(
int doc)
468 int v2 = currentReaderValues[doc];
473 else if (bottom < v2)
483 public override void Copy(
int slot,
int doc)
485 values[slot] = currentReaderValues[doc];
488 public override void SetNextReader(
IndexReader reader,
int docBase)
490 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetInts(reader, field, parser);
493 public override void SetBottom(
int bottom)
495 this.bottom = values[bottom];
498 public override IComparable
this[
int slot]
500 get {
return (System.Int32) values[slot]; }
509 private long[] values;
510 private long[] currentReaderValues;
511 private System.String field;
515 internal LongComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
517 values =
new long[numHits];
522 public override int Compare(
int slot1,
int slot2)
526 long v1 = values[slot1];
527 long v2 = values[slot2];
542 public override int CompareBottom(
int doc)
546 long v2 = currentReaderValues[doc];
551 else if (bottom < v2)
561 public override void Copy(
int slot,
int doc)
563 values[slot] = currentReaderValues[doc];
566 public override void SetNextReader(
IndexReader reader,
int docBase)
568 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetLongs(reader, field, parser);
571 public override void SetBottom(
int bottom)
573 this.bottom = values[bottom];
576 public override IComparable
this[
int slot]
578 get {
return (
long) values[slot]; }
591 private float[] scores;
592 private float bottom;
597 scores =
new float[numHits];
600 public override int Compare(
int slot1,
int slot2)
602 float score1 = scores[slot1];
603 float score2 = scores[slot2];
604 return score1 > score2?- 1:(score1 < score2?1:0);
607 public override int CompareBottom(
int doc)
609 float score = scorer.Score();
610 return bottom > score?- 1:(bottom < score?1:0);
613 public override void Copy(
int slot,
int doc)
615 scores[slot] = scorer.Score();
618 public override void SetNextReader(
IndexReader reader,
int docBase)
622 public override void SetBottom(
int bottom)
624 this.bottom = scores[bottom];
627 public override void SetScorer(
Scorer scorer)
634 public override IComparable
this[
int slot]
636 get {
return (
float) scores[slot]; }
645 private short[] values;
646 private short[] currentReaderValues;
647 private System.String field;
649 private short bottom;
651 internal ShortComparator(
int numHits, System.String field, Lucene.Net.Search.Parser parser)
653 values =
new short[numHits];
658 public override int Compare(
int slot1,
int slot2)
660 return values[slot1] - values[slot2];
663 public override int CompareBottom(
int doc)
665 return bottom - currentReaderValues[doc];
668 public override void Copy(
int slot,
int doc)
670 values[slot] = currentReaderValues[doc];
673 public override void SetNextReader(
IndexReader reader,
int docBase)
675 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetShorts(reader, field, parser);
678 public override void SetBottom(
int bottom)
680 this.bottom = values[bottom];
683 public override IComparable
this[
int slot]
685 get {
return (
short) values[slot]; }
695 private System.String[] values;
696 private System.String[] currentReaderValues;
697 private System.String field;
698 internal System.Globalization.CompareInfo collator;
699 private System.String bottom;
701 internal StringComparatorLocale(
int numHits, System.String field, System.Globalization.CultureInfo locale)
703 values =
new System.String[numHits];
705 collator = locale.CompareInfo;
708 public override int Compare(
int slot1,
int slot2)
710 System.String val1 = values[slot1];
711 System.String val2 = values[slot2];
720 else if (val2 == null)
724 return collator.
Compare(val1.ToString(), val2.ToString());
727 public override int CompareBottom(
int doc)
729 System.String val2 = currentReaderValues[doc];
738 else if (val2 == null)
742 return collator.Compare(bottom.ToString(), val2.ToString());
745 public override void Copy(
int slot,
int doc)
747 values[slot] = currentReaderValues[doc];
750 public override void SetNextReader(
IndexReader reader,
int docBase)
752 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStrings(reader, field);
755 public override void SetBottom(
int bottom)
757 this.bottom = values[bottom];
760 public override IComparable
this[
int slot]
762 get {
return values[slot]; }
780 private System.String[] values;
781 private int[] readerGen;
783 private int currentReaderGen = - 1;
784 private System.String[] lookup;
786 private System.String field;
788 private int bottomSlot = - 1;
789 private int bottomOrd;
790 private System.String bottomValue;
791 private bool reversed;
796 ords =
new int[numHits];
797 values =
new System.String[numHits];
798 readerGen =
new int[numHits];
799 this.sortPos = sortPos;
800 this.reversed = reversed;
804 public override int Compare(
int slot1,
int slot2)
806 if (readerGen[slot1] == readerGen[slot2])
808 int cmp = ords[slot1] - ords[slot2];
815 System.String val1 = values[slot1];
816 System.String val2 = values[slot2];
825 else if (val2 == null)
829 return String.CompareOrdinal(val1, val2);
832 public override int CompareBottom(
int doc)
834 System.Diagnostics.Debug.Assert(bottomSlot != - 1);
835 int order = this.order[doc];
836 int cmp = bottomOrd - order;
842 System.String val2 = lookup[order];
843 if (bottomValue == null)
852 else if (val2 == null)
857 return String.CompareOrdinal(bottomValue, val2);
860 private void Convert(
int slot)
862 readerGen[slot] = currentReaderGen;
864 System.String value_Renamed = values[slot];
865 if (value_Renamed == null)
871 if (sortPos == 0 && bottomSlot != - 1 && bottomSlot != slot)
875 System.Diagnostics.Debug.Assert(bottomOrd < lookup.Length);
878 index = BinarySearch(lookup, value_Renamed, bottomOrd, lookup.Length - 1);
882 index = BinarySearch(lookup, value_Renamed, 0, bottomOrd);
888 index = BinarySearch(lookup, value_Renamed);
898 public override void Copy(
int slot,
int doc)
900 int ord = order[doc];
902 System.Diagnostics.Debug.Assert(ord >= 0);
903 values[slot] = lookup[ord];
904 readerGen[slot] = currentReaderGen;
907 public override void SetNextReader(
IndexReader reader,
int docBase)
909 StringIndex currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStringIndex(reader, field);
911 order = currentReaderValues.
order;
912 lookup = currentReaderValues.
lookup;
913 System.Diagnostics.Debug.Assert(lookup.Length > 0);
914 if (bottomSlot != - 1)
917 bottomOrd = ords[bottomSlot];
921 public override void SetBottom(
int bottom)
924 if (readerGen[bottom] != currentReaderGen)
928 bottomOrd = ords[bottom];
929 System.Diagnostics.Debug.Assert(bottomOrd >= 0);
930 System.Diagnostics.Debug.Assert(bottomOrd < lookup.Length);
931 bottomValue = values[bottom];
934 public override IComparable
this[
int slot]
936 get {
return values[slot]; }
939 public string[] GetValues()
944 public int BottomSlot
946 get {
return bottomSlot; }
951 get {
return field; }
963 private System.String[] values;
964 private System.String[] currentReaderValues;
965 private System.String field;
966 private System.String bottom;
970 values =
new System.String[numHits];
974 public override int Compare(
int slot1,
int slot2)
976 System.String val1 = values[slot1];
977 System.String val2 = values[slot2];
986 else if (val2 == null)
991 return String.CompareOrdinal(val1, val2);
994 public override int CompareBottom(
int doc)
996 System.String val2 = currentReaderValues[doc];
1005 else if (val2 == null)
1009 return String.CompareOrdinal(bottom, val2);
1012 public override void Copy(
int slot,
int doc)
1014 values[slot] = currentReaderValues[doc];
1019 currentReaderValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStrings(reader, field);
1022 public override void SetBottom(
int bottom)
1024 this.bottom = values[bottom];
1027 public override IComparable
this[
int slot]
1029 get {
return values[slot]; }
1033 protected internal static int BinarySearch(System.String[] a, System.String key)
1035 return BinarySearch(a, key, 0, a.Length - 1);
1038 protected internal static int BinarySearch(System.String[] a, System.String key,
int low,
int high)
1044 System.String midVal = a[mid];
1048 cmp = String.CompareOrdinal(midVal, key);