GetComparator() public method

Returns the FieldComparator to use for sorting. @lucene.experimental
public GetComparator ( int numHits, int sortPos ) : FieldComparator
numHits int number of top hits the queue will store
sortPos int position of this SortField within {@link /// Sort}. The comparator is primary if sortPos==0, /// secondary if sortPos==1, etc. Some comparators can /// optimize themselves when they are the primary sort.
return FieldComparator
Ejemplo n.º 1
0
            public MultiComparatorsFieldValueHitQueue(SortField[] fields, int size)
                : base(fields, size)
            {
                int numComparators = comparators.Length;

                for (int i = 0; i < numComparators; ++i)
                {
                    SortField field = fields[i];

                    ReverseMul[i] = field.reverse ? -1 : 1;
                    SetComparator(i, field.GetComparator(size, i));
                }
            }
Ejemplo n.º 2
0
            public MultiComparatorsFieldValueHitQueue(ArraySegment <SortField> fields, int size) : base(fields)
            {
                int numComparators = comparators.Length;

                for (int i = 0; i < numComparators; ++i)
                {
                    SortField field = fields.Array[i + fields.Offset];

                    reverseMul[i]  = field.reverse?-1:1;
                    comparators[i] = field.GetComparator(size, i);
                }

                Initialize(size);
            }
Ejemplo n.º 3
0
            public OneComparatorFieldValueHitQueue(SortField[] fields, int size)
                : base(fields, size)
            {
                if (fields.Length == 0)
                {
                    throw new System.ArgumentException("Sort must contain at least one field");
                }

                SortField field = fields[0];

                SetComparator(0, field.GetComparator(size, 0));
                oneReverseMul = field.reverse ? -1 : 1;

                ReverseMul[0] = oneReverseMul;
            }
Ejemplo n.º 4
0
            public MultiComparatorsFieldValueHitQueue(SortField[] fields, int size) : base(fields)
            {
                int numComparators = comparators.Length;

                for (int i = 0; i < numComparators; ++i)
                {
                    SortField field = fields[i];

                    // AUTO is resolved before we are called
                    System.Diagnostics.Debug.Assert(field.GetType() != SortField.AUTO);

                    reverseMul[i]  = field.reverse?-1:1;
                    comparators[i] = field.GetComparator(size, i);
                }

                Initialize(size);
            }
Ejemplo n.º 5
0
            public OneComparatorFieldValueHitQueue(ArraySegment <SortField> fields, int size) : base(fields)
            {
                if (fields.Count == 0)
                {
                    throw new System.ArgumentException("Sort must contain at least one field");
                }

                SortField field = fields.Array[0 + fields.Offset];

                comparator    = field.GetComparator(size, 0);
                oneReverseMul = field.reverse?-1:1;

                comparators[0] = comparator;
                reverseMul[0]  = oneReverseMul;

                Initialize(size);
            }
Ejemplo n.º 6
0
            public OneComparatorFieldValueHitQueue(SortField[] fields, int size) : base(fields)
            {
                if (fields.Length == 0)
                {
                    throw new System.ArgumentException("Sort must contain at least one field");
                }

                SortField field = fields[0];

                // AUTO is resolved before we are called
                System.Diagnostics.Debug.Assert(field.GetType() != SortField.AUTO);
                comparator    = field.GetComparator(size, 0);
                oneReverseMul = field.reverse?-1:1;

                comparators[0] = comparator;
                reverseMul[0]  = oneReverseMul;

                Initialize(size);
            }
Ejemplo n.º 7
0
            public MergeSortQueue(Sort sort, TopDocs[] shardHits)
                : base(shardHits.Length)
            {
                this.ShardHits = new ScoreDoc[shardHits.Length][];
                for (int shardIDX = 0; shardIDX < shardHits.Length; shardIDX++)
                {
                    ScoreDoc[] shard = shardHits[shardIDX].ScoreDocs;
                    //System.out.println("  init shardIdx=" + shardIDX + " hits=" + shard);
                    if (shard != null)
                    {
                        this.ShardHits[shardIDX] = shard;
                        // Fail gracefully if API is misused:
                        for (int hitIDX = 0; hitIDX < shard.Length; hitIDX++)
                        {
                            ScoreDoc sd = shard[hitIDX];
                            if (!(sd is FieldDoc))
                            {
                                throw new System.ArgumentException("shard " + shardIDX + " was not sorted by the provided Sort (expected FieldDoc but got ScoreDoc)");
                            }
                            FieldDoc fd = (FieldDoc)sd;
                            if (fd.Fields == null)
                            {
                                throw new System.ArgumentException("shard " + shardIDX + " did not set sort field values (FieldDoc.fields is null); you must pass fillFields=true to IndexSearcher.search on each shard");
                            }
                        }
                    }
                }

                SortField[] sortFields = sort.GetSort();
                comparators = new FieldComparator[sortFields.Length];
                ReverseMul  = new int[sortFields.Length];
                for (int compIDX = 0; compIDX < sortFields.Length; compIDX++)
                {
                    SortField sortField = sortFields[compIDX];
                    comparators[compIDX] = sortField.GetComparator(1, compIDX);
                    ReverseMul[compIDX]  = sortField.Reverse ? -1 : 1;
                }
            }