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

Add BytesRefIterator to TermInSetQuery #13806

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -27,13 +27,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.BytesRefComparator;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.StringSorter;
import org.apache.lucene.util.*;
import org.apache.lucene.util.automaton.Automata;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.ByteRunAutomaton;
Expand Down Expand Up @@ -141,6 +135,11 @@ public long getTermsCount() {
return termData.size();
}

public BytesRefIterator getBytesRefIterator() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add javadocs for the method and @experimental for now?

its possible we could "fix visitor" api in the future where we wouldn't need this public method specific to this query as well (see general thoughts on PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks.

final TermIterator iterator = this.termData.iterator();
return () -> iterator.next();
}

@Override
public void visit(QueryVisitor visitor) {
if (visitor.acceptField(field) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.lucene.tests.util.RamUsageTester;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefIterator;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.automaton.ByteRunAutomaton;

Expand Down Expand Up @@ -527,4 +528,19 @@ public void consumeTermsMatching(
}
});
}

public void testTermsIterator() throws IOException {
TermInSetQuery empty = new TermInSetQuery("field", Collections.emptyList());
BytesRefIterator it = empty.getBytesRefIterator();
assertNull(it.next());

TermInSetQuery query =
new TermInSetQuery(
"field", List.of(newBytesRef("term1"), newBytesRef("term2"), newBytesRef("term3")));
it = query.getBytesRefIterator();
assertEquals(newBytesRef("term1"), it.next());
assertEquals(newBytesRef("term2"), it.next());
assertEquals(newBytesRef("term3"), it.next());
assertNull(it.next());
}
}