org.apache.lucene.search.LeafFieldComparator Java Examples
The following examples show how to use
org.apache.lucene.search.LeafFieldComparator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NullFieldComparatorSource.java From crate with Apache License 2.0 | 6 votes |
@Override public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) { return new FieldComparator<>() { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) { return LEAF_FIELD_COMPARATOR; } @Override public int compare(int slot1, int slot2) { return 0; } @Override public void setTopValue(Object value) { } @Override public Object value(int slot) { return nullSentinel; } }; }
Example #2
Source File: NullFieldComparatorSource.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { return new FieldComparator<Object>() { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return LEAF_FIELD_COMPARATOR; } @Override public int compare(int slot1, int slot2) { return 0; } @Override public void setTopValue(Object value) { } @Override public Object value(int slot) { return missingValue; } }; }
Example #3
Source File: LatLonPointSpatialField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { return new DoubleValues() { @SuppressWarnings("unchecked") final FieldComparator<Double> comparator = (FieldComparator<Double>) getSortField(false).getComparator(1, 1); final LeafFieldComparator leafComparator = comparator.getLeafComparator(ctx); final double mult = multiplier; // so it's a local field double value = Double.POSITIVE_INFINITY; @Override public double doubleValue() throws IOException { return value; } @Override public boolean advanceExact(int doc) throws IOException { leafComparator.copy(0, doc); value = comparator.value(0) * mult; return true; } }; }
Example #4
Source File: CollapsingQParserPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes"}) public SortFieldsCompare(SortField[] sorts, int initNumGroups) { this.sorts = sorts; numClauses = sorts.length; fieldComparators = new FieldComparator[numClauses]; leafFieldComparators = new LeafFieldComparator[numClauses]; reverseMul = new int[numClauses]; for (int clause = 0; clause < numClauses; clause++) { SortField sf = sorts[clause]; // we only need one slot for every comparator fieldComparators[clause] = sf.getComparator(1, clause); reverseMul[clause] = sf.getReverse() ? -1 : 1; } groupHeadValues = new Object[initNumGroups][]; nullGroupValues = new Object[numClauses]; }
Example #5
Source File: BlockGroupingCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void setScorer(Scorable scorer) throws IOException { this.scorer = scorer; for (LeafFieldComparator comparator : leafComparators) { comparator.setScorer(scorer); } }
Example #6
Source File: InputFieldComparator.java From crate with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { for (int i = 0; i < collectorExpressions.size(); i++) { collectorExpressions.get(i).setNextReader(context); } return this; }
Example #7
Source File: LatLonPointDistanceComparator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info != null) { LatLonDocValuesField.checkCompatible(info); } currentDocs = DocValues.getSortedNumeric(reader, field); valuesDocID = -1; return this; }
Example #8
Source File: XYPointDistanceComparator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info != null) { XYDocValuesField.checkCompatible(info); } currentDocs = DocValues.getSortedNumeric(reader, field); valuesDocID = -1; return this; }
Example #9
Source File: FirstPassGroupingCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void setScorer(Scorable scorer) throws IOException { groupSelector.setScorer(scorer); for (LeafFieldComparator comparator : leafComparators) { comparator.setScorer(scorer); } }
Example #10
Source File: FirstPassGroupingCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Create the first pass collector. * * @param groupSelector a GroupSelector used to defined groups * @param groupSort The {@link Sort} used to sort the * groups. The top sorted document within each group * according to groupSort, determines how that group * sorts against other groups. This must be non-null, * ie, if you want to groupSort by relevance use * Sort.RELEVANCE. * @param topNGroups How many top groups to keep. */ @SuppressWarnings({"unchecked", "rawtypes"}) public FirstPassGroupingCollector(GroupSelector<T> groupSelector, Sort groupSort, int topNGroups) { this.groupSelector = groupSelector; if (topNGroups < 1) { throw new IllegalArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")"); } // TODO: allow null groupSort to mean "by relevance", // and specialize it? this.topNGroups = topNGroups; this.needsScores = groupSort.needsScores(); final SortField[] sortFields = groupSort.getSort(); comparators = new FieldComparator[sortFields.length]; leafComparators = new LeafFieldComparator[sortFields.length]; compIDXEnd = comparators.length - 1; reversed = new int[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { final SortField sortField = sortFields[i]; // use topNGroups + 1 so we have a spare slot to use for comparing (tracked by this.spareSlot): comparators[i] = sortField.getComparator(topNGroups + 1, i); reversed[i] = sortField.getReverse() ? -1 : 1; } spareSlot = topNGroups; groupMap = new HashMap<>(topNGroups); }
Example #11
Source File: BlockGroupingCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Create the single pass collector. * * @param groupSort The {@link Sort} used to sort the * groups. The top sorted document within each group * according to groupSort, determines how that group * sorts against other groups. This must be non-null, * ie, if you want to groupSort by relevance use * Sort.RELEVANCE. * @param topNGroups How many top groups to keep. * @param needsScores true if the collected documents * require scores, either because relevance is included * in the withinGroupSort or because you plan to pass true * for either getSscores or getMaxScores to {@link * #getTopGroups} * @param lastDocPerGroup a {@link Weight} that marks the * last document in each group. */ public BlockGroupingCollector(Sort groupSort, int topNGroups, boolean needsScores, Weight lastDocPerGroup) { if (topNGroups < 1) { throw new IllegalArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")"); } groupQueue = new GroupQueue(topNGroups); pendingSubDocs = new int[10]; if (needsScores) { pendingSubScores = new float[10]; } this.needsScores = needsScores; this.lastDocPerGroup = lastDocPerGroup; this.groupSort = groupSort; this.topNGroups = topNGroups; final SortField[] sortFields = groupSort.getSort(); comparators = new FieldComparator<?>[sortFields.length]; leafComparators = new LeafFieldComparator[sortFields.length]; compIDXEnd = comparators.length - 1; reversed = new int[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { final SortField sortField = sortFields[i]; comparators[i] = sortField.getComparator(topNGroups, i); reversed[i] = sortField.getReverse() ? -1 : 1; } }
Example #12
Source File: AllGroupHeadsCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void updateDocHead(int doc) throws IOException { for (LeafFieldComparator comparator : leafComparators) { comparator.copy(0, doc); comparator.setBottom(0); } this.doc = doc + docBase; }
Example #13
Source File: AllGroupHeadsCollector.java From lucene-solr with Apache License 2.0 | 5 votes |
protected SortingGroupHead(Sort sort, T groupValue, int doc, LeafReaderContext context, Scorable scorer) throws IOException { super(groupValue, doc, context.docBase); final SortField[] sortFields = sort.getSort(); comparators = new FieldComparator[sortFields.length]; leafComparators = new LeafFieldComparator[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { comparators[i] = sortFields[i].getComparator(1, i); leafComparators[i] = comparators[i].getLeafComparator(context); leafComparators[i].setScorer(scorer); leafComparators[i].copy(0, doc); leafComparators[i].setBottom(0); } }
Example #14
Source File: Geo3DPointDistanceComparator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info != null) { Geo3DDocValuesField.checkCompatible(info); } currentDocs = DocValues.getSortedNumeric(reader, field); return this; }
Example #15
Source File: Geo3DPointOutsideDistanceComparator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(field); if (info != null) { Geo3DDocValuesField.checkCompatible(info); } currentDocs = DocValues.getSortedNumeric(reader, field); return this; }
Example #16
Source File: AlfrescoCollatableMLTextFieldType.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { docTerms = DocValues.getBinary(context.reader(), field); docsWithField = DocValues.getDocsWithField(context.reader(), field); if (docsWithField instanceof Bits.MatchAllBits) { docsWithField = null; } return this; }
Example #17
Source File: AlfrescoCollatableTextFieldType.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { docTerms = DocValues.getBinary(context.reader(), field); docsWithField = DocValues.getDocsWithField(context.reader(), field); if (docsWithField instanceof Bits.MatchAllBits) { docsWithField = null; } return this; }
Example #18
Source File: InputFieldComparator.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { for (LuceneCollectorExpression collectorExpression : collectorExpressions) { collectorExpression.setNextReader(context); } return this; }
Example #19
Source File: FieldsVisitorInputFieldComparator.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { currentReader = context.reader(); return super.getLeafComparator(context); }
Example #20
Source File: AllGroupHeadsCollector.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected void setScorer(Scorable scorer) throws IOException { for (LeafFieldComparator c : leafComparators) { c.setScorer(scorer); } }
Example #21
Source File: CheckIndex.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Tests index sort order. * @lucene.experimental */ public static Status.IndexSortStatus testSort(CodecReader reader, Sort sort, PrintStream infoStream, boolean failFast) throws IOException { // This segment claims its documents are sorted according to the incoming sort ... let's make sure: long startNS = System.nanoTime(); Status.IndexSortStatus status = new Status.IndexSortStatus(); if (sort != null) { if (infoStream != null) { infoStream.print(" test: index sort.........."); } SortField fields[] = sort.getSort(); final int reverseMul[] = new int[fields.length]; final LeafFieldComparator comparators[] = new LeafFieldComparator[fields.length]; LeafReaderContext readerContext = new LeafReaderContext(reader); for (int i = 0; i < fields.length; i++) { reverseMul[i] = fields[i].getReverse() ? -1 : 1; comparators[i] = fields[i].getComparator(1, i).getLeafComparator(readerContext); } int maxDoc = reader.maxDoc(); try { for(int docID=1;docID < maxDoc;docID++) { int cmp = 0; for (int i = 0; i < comparators.length; i++) { // TODO: would be better if copy() didnt cause a term lookup in TermOrdVal & co, // the segments are always the same here... comparators[i].copy(0, docID-1); comparators[i].setBottom(0); cmp = reverseMul[i] * comparators[i].compareBottom(docID); if (cmp != 0) { break; } } if (cmp > 0) { throw new RuntimeException("segment has indexSort=" + sort + " but docID=" + (docID-1) + " sorts after docID=" + docID); } } msg(infoStream, String.format(Locale.ROOT, "OK [took %.3f sec]", nsToSec(System.nanoTime()-startNS))); } catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e); } msg(infoStream, "ERROR [" + String.valueOf(e.getMessage()) + "]"); status.error = e; if (infoStream != null) { e.printStackTrace(infoStream); } } } return status; }
Example #22
Source File: ChildFieldValueSourceParser.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return byteRefs.getLeafComparator(context); }