Skip to content

Commit 8b7f42e

Browse files
authored
Refactor: Add EmptyHitCounter for use in MatchHashesAndScoreQuerySuite (#601)
1 parent 2c20ce5 commit 8b7f42e

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.klibisz.elastiknn.search;
2+
3+
import org.apache.lucene.search.KthGreatest;
4+
5+
public final class EmptyHitCounter implements HitCounter {
6+
@Override
7+
public void increment(int key, short count) {}
8+
9+
@Override
10+
public void increment(int key, int count) {}
11+
12+
@Override
13+
public boolean isEmpty() {
14+
return true;
15+
}
16+
17+
@Override
18+
public short get(int key) {
19+
return 0;
20+
}
21+
22+
@Override
23+
public int numHits() {
24+
return 0;
25+
}
26+
27+
@Override
28+
public int capacity() {
29+
return 0;
30+
}
31+
32+
@Override
33+
public int minKey() {
34+
return 0;
35+
}
36+
37+
@Override
38+
public int maxKey() {
39+
return 0;
40+
}
41+
42+
@Override
43+
public KthGreatest.Result kthGreatest(int k) {
44+
return new KthGreatest.Result((short) 0, 0, 0);
45+
}
46+
}

elastiknn-lucene/src/main/java/org/apache/lucene/search/MatchHashesAndScoreQuery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.klibisz.elastiknn.models.HashAndFreq;
44
import com.klibisz.elastiknn.search.ArrayHitCounter;
5+
import com.klibisz.elastiknn.search.EmptyHitCounter;
56
import com.klibisz.elastiknn.search.HitCounter;
67
import org.apache.lucene.index.*;
78
import org.apache.lucene.util.BytesRef;
@@ -58,7 +59,7 @@ private HitCounter countHits(LeafReader reader) throws IOException {
5859
Terms terms = reader.terms(field);
5960
// terms seem to be null after deleting docs. https://github.com/alexklibisz/elastiknn/issues/158
6061
if (terms == null) {
61-
return new ArrayHitCounter(0);
62+
return new EmptyHitCounter();
6263
} else {
6364
TermsEnum termsEnum = terms.iterator();
6465
PostingsEnum docs = null;

0 commit comments

Comments
 (0)