mirror of https://github.com/apache/lucene.git
short-circuit for case there is no oversample
This commit is contained in:
parent
feda6af1a7
commit
3178bbc22e
|
@ -55,6 +55,10 @@ public class RerankKnnFloatVectorQuery extends Query {
|
||||||
public Query rewrite(IndexSearcher indexSearcher) throws IOException {
|
public Query rewrite(IndexSearcher indexSearcher) throws IOException {
|
||||||
IndexReader reader = indexSearcher.getIndexReader();
|
IndexReader reader = indexSearcher.getIndexReader();
|
||||||
Query rewritten = indexSearcher.rewrite(query);
|
Query rewritten = indexSearcher.rewrite(query);
|
||||||
|
// short-circuit: don't re-rank if we already got all possible results
|
||||||
|
if (query.getK() <= k) {
|
||||||
|
return rewritten;
|
||||||
|
}
|
||||||
Weight weight = indexSearcher.createWeight(rewritten, ScoreMode.COMPLETE_NO_SCORES, 1.0f);
|
Weight weight = indexSearcher.createWeight(rewritten, ScoreMode.COMPLETE_NO_SCORES, 1.0f);
|
||||||
HitQueue queue = new HitQueue(k, false);
|
HitQueue queue = new HitQueue(k, false);
|
||||||
for (var leaf : reader.leaves()) {
|
for (var leaf : reader.leaves()) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class TestRerankKnnFloatVectorQuery extends LuceneTestCase {
|
||||||
IndexSearcher searcher = new IndexSearcher(reader);
|
IndexSearcher searcher = new IndexSearcher(reader);
|
||||||
float[] targetVector = randomFloatVector(VECTOR_DIMENSION, random);
|
float[] targetVector = randomFloatVector(VECTOR_DIMENSION, random);
|
||||||
int k = 10;
|
int k = 10;
|
||||||
double oversample = 1.0;
|
double oversample = random.nextFloat(1.5f, 3.0f);
|
||||||
|
|
||||||
KnnFloatVectorQuery knnQuery =
|
KnnFloatVectorQuery knnQuery =
|
||||||
new KnnFloatVectorQuery(FIELD, targetVector, k + (int) (k * oversample));
|
new KnnFloatVectorQuery(FIELD, targetVector, k + (int) (k * oversample));
|
||||||
|
|
Loading…
Reference in New Issue