Skip to content

Commit

Permalink
Refactor: Add EmptyHitCounter for use in MatchHashesAndScoreQuerySuite (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexklibisz authored Nov 27, 2023
1 parent 2c20ce5 commit 8b7f42e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.klibisz.elastiknn.search;

import org.apache.lucene.search.KthGreatest;

public final class EmptyHitCounter implements HitCounter {
@Override
public void increment(int key, short count) {}

@Override
public void increment(int key, int count) {}

@Override
public boolean isEmpty() {
return true;
}

@Override
public short get(int key) {
return 0;
}

@Override
public int numHits() {
return 0;
}

@Override
public int capacity() {
return 0;
}

@Override
public int minKey() {
return 0;
}

@Override
public int maxKey() {
return 0;
}

@Override
public KthGreatest.Result kthGreatest(int k) {
return new KthGreatest.Result((short) 0, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.klibisz.elastiknn.models.HashAndFreq;
import com.klibisz.elastiknn.search.ArrayHitCounter;
import com.klibisz.elastiknn.search.EmptyHitCounter;
import com.klibisz.elastiknn.search.HitCounter;
import org.apache.lucene.index.*;
import org.apache.lucene.util.BytesRef;
Expand Down Expand Up @@ -58,7 +59,7 @@ private HitCounter countHits(LeafReader reader) throws IOException {
Terms terms = reader.terms(field);
// terms seem to be null after deleting docs. https://github.com/alexklibisz/elastiknn/issues/158
if (terms == null) {
return new ArrayHitCounter(0);
return new EmptyHitCounter();
} else {
TermsEnum termsEnum = terms.iterator();
PostingsEnum docs = null;
Expand Down

0 comments on commit 8b7f42e

Please sign in to comment.