Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.apache.lucene.queries;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.Weight;
import org.elasticsearch.common.lucene.Lucene;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
/**
* A {@link Query} that only matches documents that are greater than the provided {@link FieldDoc}.
* This works only if the index is sorted according to the given search {@link Sort}.
*/
public class SearchAfterSortedDocQuery extends Query {
private final Sort sort;
private final FieldDoc after;
private final FieldComparator[] fieldComparators;
private final int[] reverseMuls;
public SearchAfterSortedDocQuery(Sort sort, FieldDoc after) {
if (sort.getSort().length != after.fields.length) {
throw new IllegalArgumentException(
"after doc has " + after.fields.length + " value(s) but sort has " + sort.getSort().length + "."
);
}
this.sort = Objects.requireNonNull(sort);
this.after = after;
int numFields = sort.getSort().length;
this.fieldComparators = new FieldComparator[numFields];
this.reverseMuls = new int[numFields];
for (int i = 0; i < numFields; i++) {
SortField sortField = sort.getSort()[i];
FieldComparator fieldComparator = sortField.getComparator(1, i);
@SuppressWarnings("unchecked")
FieldComparator