Exemplo n.º 1
0
        /// <summary>
        /// Creates a new sorted wrapper, sorting by BytesRef
        /// (ascending) then cost (ascending).
        /// </summary>
        public SortedTermFreqEnumeratorWrapper(ITermFreqEnumerator source, IComparer <BytesRef> comparer)
        {
            this.source   = source;
            this.comparer = comparer;
            this.reader   = Sort();
            this.tieBreakByCostComparer = Comparer <BytesRef> .Create((left, right) =>
            {
                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       = Decode(leftScratch, input);
                long rightCost      = Decode(rightScratch, input);
                int cmp             = comparer.Compare(leftScratch, rightScratch);
                if (cmp != 0)
                {
                    return(cmp);
                }
                return(leftCost.CompareTo(rightCost));
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new iterator, buffering entries from the specified iterator
        /// </summary>
        public BufferingTermFreqEnumeratorWrapper(ITermFreqEnumerator source)
        {
            this.comp = source.Comparer;
            int freqIndex = 0;

            while (source.MoveNext())
            {
                m_entries.Append(source.Current);
                if (freqIndex >= m_freqs.Length)
                {
                    m_freqs = ArrayUtil.Grow(m_freqs, m_freqs.Length + 1);
                }
                m_freqs[freqIndex++] = source.Weight;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new sorted wrapper, using <see cref="BytesRef.UTF8SortedAsUnicodeComparer"/>
 /// for sorting.
 /// </summary>
 public SortedTermFreqEnumeratorWrapper(ITermFreqEnumerator source)
     : this(source, BytesRef.UTF8SortedAsUnicodeComparer)
 {
 }