mirror of https://github.com/apache/lucene.git
Fix test failure TestKnnByteVectorQuery#testTimeLimitingKnnCollectorManager (#13312)
This commit is contained in:
parent
3d86ff2e6a
commit
f665bd196e
|
@ -42,54 +42,62 @@ public class TimeLimitingKnnCollectorManager implements KnnCollectorManager {
|
||||||
if (queryTimeout == null) {
|
if (queryTimeout == null) {
|
||||||
return collector;
|
return collector;
|
||||||
}
|
}
|
||||||
return new KnnCollector() {
|
return new TimeLimitingKnnCollector(collector);
|
||||||
@Override
|
}
|
||||||
public boolean earlyTerminated() {
|
|
||||||
return queryTimeout.shouldExit() || collector.earlyTerminated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
class TimeLimitingKnnCollector implements KnnCollector {
|
||||||
public void incVisitedCount(int count) {
|
private final KnnCollector collector;
|
||||||
collector.incVisitedCount(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
TimeLimitingKnnCollector(KnnCollector collector) {
|
||||||
public long visitedCount() {
|
this.collector = collector;
|
||||||
return collector.visitedCount();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long visitLimit() {
|
public boolean earlyTerminated() {
|
||||||
return collector.visitLimit();
|
return queryTimeout.shouldExit() || collector.earlyTerminated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int k() {
|
public void incVisitedCount(int count) {
|
||||||
return collector.k();
|
collector.incVisitedCount(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean collect(int docId, float similarity) {
|
public long visitedCount() {
|
||||||
return collector.collect(docId, similarity);
|
return collector.visitedCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float minCompetitiveSimilarity() {
|
public long visitLimit() {
|
||||||
return collector.minCompetitiveSimilarity();
|
return collector.visitLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TopDocs topDocs() {
|
public int k() {
|
||||||
TopDocs docs = collector.topDocs();
|
return collector.k();
|
||||||
|
}
|
||||||
|
|
||||||
// Mark results as partial if timeout is met
|
@Override
|
||||||
TotalHits.Relation relation =
|
public boolean collect(int docId, float similarity) {
|
||||||
queryTimeout.shouldExit()
|
return collector.collect(docId, similarity);
|
||||||
? TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
|
}
|
||||||
: docs.totalHits.relation;
|
|
||||||
|
|
||||||
return new TopDocs(new TotalHits(docs.totalHits.value, relation), docs.scoreDocs);
|
@Override
|
||||||
}
|
public float minCompetitiveSimilarity() {
|
||||||
};
|
return collector.minCompetitiveSimilarity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TopDocs topDocs() {
|
||||||
|
TopDocs docs = collector.topDocs();
|
||||||
|
|
||||||
|
// Mark results as partial if timeout is met
|
||||||
|
TotalHits.Relation relation =
|
||||||
|
queryTimeout.shouldExit()
|
||||||
|
? TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
|
||||||
|
: docs.totalHits.relation;
|
||||||
|
|
||||||
|
return new TopDocs(new TotalHits(docs.totalHits.value, relation), docs.scoreDocs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -785,7 +785,8 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
|
||||||
noTimeoutManager.newCollector(Integer.MAX_VALUE, searcher.leafContexts.get(0));
|
noTimeoutManager.newCollector(Integer.MAX_VALUE, searcher.leafContexts.get(0));
|
||||||
|
|
||||||
// Check that a normal collector is created without timeout
|
// Check that a normal collector is created without timeout
|
||||||
assertTrue(noTimeoutCollector instanceof TopKnnCollector);
|
assertFalse(
|
||||||
|
noTimeoutCollector instanceof TimeLimitingKnnCollectorManager.TimeLimitingKnnCollector);
|
||||||
noTimeoutCollector.collect(0, 0);
|
noTimeoutCollector.collect(0, 0);
|
||||||
assertFalse(noTimeoutCollector.earlyTerminated());
|
assertFalse(noTimeoutCollector.earlyTerminated());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue