Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Add EmptyHitCounter for use in MatchHashesAndScoreQuery #601

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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