-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expose iterator over query terms in TermInSetQuery #12280
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/PKTermInSetQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.apache.lucene.sandbox.search; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import org.apache.lucene.index.ImpactsEnum; | ||
import org.apache.lucene.index.PostingsEnum; | ||
import org.apache.lucene.index.TermState; | ||
import org.apache.lucene.index.Terms; | ||
import org.apache.lucene.index.TermsEnum; | ||
import org.apache.lucene.search.TermInSetQuery; | ||
import org.apache.lucene.util.AttributeSource; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.apache.lucene.util.BytesRefIterator; | ||
|
||
/** | ||
* {@link TermInSetQuery} optimized for a primary key-like field. | ||
* | ||
* <p>Relies on {@link TermsEnum#seekExact(BytesRef)} instead of {@link | ||
* TermsEnum#seekCeil(BytesRef)} to produce a terms iterator, which is compatible with {@code | ||
* BloomFilteringPostingsFormat}. | ||
*/ | ||
public class PKTermInSetQuery extends TermInSetQuery { | ||
public PKTermInSetQuery(String field, Collection<BytesRef> terms) { | ||
super(field, terms); | ||
} | ||
|
||
public PKTermInSetQuery(String field, BytesRef... terms) { | ||
super(field, terms); | ||
} | ||
|
||
public PKTermInSetQuery(RewriteMethod rewriteMethod, String field, Collection<BytesRef> terms) { | ||
super(rewriteMethod, field, terms); | ||
} | ||
|
||
public PKTermInSetQuery(RewriteMethod rewriteMethod, String field, BytesRef... terms) { | ||
super(rewriteMethod, field, terms); | ||
} | ||
|
||
@Override | ||
protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException { | ||
final TermsEnum tEnum = terms.iterator(); | ||
final BytesRefIterator queryTerms = getQueryTerms(); | ||
|
||
return new TermsEnum() { | ||
@Override | ||
public BytesRef next() throws IOException { | ||
BytesRef nextTerm; | ||
while ((nextTerm = queryTerms.next()) != null) { | ||
if (tEnum.seekExact(nextTerm)) { | ||
break; | ||
} | ||
} | ||
return nextTerm; | ||
} | ||
|
||
@Override | ||
public AttributeSource attributes() { | ||
return tEnum.attributes(); | ||
} | ||
|
||
@Override | ||
public BytesRef term() throws IOException { | ||
return tEnum.term(); | ||
} | ||
|
||
@Override | ||
public long ord() throws IOException { | ||
return tEnum.ord(); | ||
} | ||
|
||
@Override | ||
public int docFreq() throws IOException { | ||
return tEnum.docFreq(); | ||
} | ||
|
||
@Override | ||
public long totalTermFreq() throws IOException { | ||
return tEnum.totalTermFreq(); | ||
} | ||
|
||
@Override | ||
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { | ||
return tEnum.postings(reuse, flags); | ||
} | ||
|
||
@Override | ||
public ImpactsEnum impacts(int flags) throws IOException { | ||
return tEnum.impacts(flags); | ||
} | ||
|
||
@Override | ||
public TermState termState() throws IOException { | ||
return tEnum.termState(); | ||
} | ||
|
||
@Override | ||
public boolean seekExact(BytesRef text) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public SeekStatus seekCeil(BytesRef text) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void seekExact(long ord) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void seekExact(BytesRef term, TermState state) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is for demo purposes only. I'm not suggesting we merge it as part of this PR. I only want to demonstrate how a class might leverage
getQueryTerms
.