Example #1
0
        /// <summary>
        /// Creates a new sorted wrapper, sorting by BytesRef
        /// (ascending) then cost (ascending).
        /// </summary>
        public SortedTermFreqIteratorWrapper(ITermFreqIterator source, IComparer <BytesRef> comparer)
        {
            this.source   = source;
            this.comparer = comparer;
            this.reader   = Sort();
            this.tieBreakByCostComparer = Comparer <BytesRef> .Create((left, right) =>
            {
                SortedTermFreqIteratorWrapper outerInstance = this;
                BytesRef leftScratch  = new BytesRef();
                BytesRef rightScratch = new BytesRef();

                ByteArrayDataInput input = new ByteArrayDataInput();
                // Make shallow copy in case decode changes the BytesRef:
                leftScratch.Bytes   = left.Bytes;
                leftScratch.Offset  = left.Offset;
                leftScratch.Length  = left.Length;
                rightScratch.Bytes  = right.Bytes;
                rightScratch.Offset = right.Offset;
                rightScratch.Length = right.Length;
                long leftCost       = outerInstance.Decode(leftScratch, input);
                long rightCost      = outerInstance.Decode(rightScratch, input);
                int cmp             = outerInstance.comparer.Compare(leftScratch, rightScratch);
                if (cmp != 0)
                {
                    return(cmp);
                }
                return(leftCost.CompareTo(rightCost));
            });
        }
Example #2
0
 /// <summary>
 /// Creates a new sorted wrapper, sorting by BytesRef
 /// (ascending) then cost (ascending).
 /// </summary>
 public SortedTermFreqIteratorWrapper(ITermFreqIterator source, IComparer <BytesRef> comparer)
 {
     this.source   = source;
     this.comparer = comparer;
     this.reader   = Sort();
     this.tieBreakByCostComparer = new ComparerAnonymousInnerClassHelper(this);
 }
        /// <summary>
        /// Creates a new iterator, buffering entries from the specified iterator
        /// </summary>
        public BufferingTermFreqIteratorWrapper(ITermFreqIterator source)
        {
            this.comp = source.Comparator;
            BytesRef spare;
            int      freqIndex = 0;

            while ((spare = source.Next()) != null)
            {
                entries.Append(spare);
                if (freqIndex >= freqs.Length)
                {
                    freqs = ArrayUtil.Grow(freqs, freqs.Length + 1);
                }
                freqs[freqIndex++] = source.Weight;
            }
        }
        /// <summary>
        /// Creates a new iterator, buffering entries from the specified iterator
        /// </summary>
        public BufferingTermFreqIteratorWrapper(ITermFreqIterator source)
        {
            this.comp = source.Comparator;
            BytesRef spare;
            int freqIndex = 0;
            while ((spare = source.Next()) != null)
            {
                entries.Append(spare);
                if (freqIndex >= freqs.Length)
                {
                    freqs = ArrayUtil.Grow(freqs, freqs.Length + 1);
                }
                freqs[freqIndex++] = source.Weight;
            }

        }
Example #5
0
 /// <summary>
 /// Creates a new sorted wrapper, using <see cref="BytesRef.UTF8SortedAsUnicodeComparer"/>
 /// for sorting.
 /// </summary>
 public SortedTermFreqIteratorWrapper(ITermFreqIterator source)
     : this(source, BytesRef.UTF8SortedAsUnicodeComparer)
 {
 }