Skip to content

Commit

Permalink
WIP: Use FieldType.getPrefixQuery in CPQP
Browse files Browse the repository at this point in the history
Causes type inference issues on the Lucene side, but providing on this
PR as an example for anyone curious.
  • Loading branch information
gerlowskija committed Jul 8, 2024
1 parent 1ad8ce0 commit df18b2b
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public QParser createParser(
*/
static class ComplexPhraseQParser extends QParser {

// Allows method-overrides for ComplexPhraseQueryParser to access 'protected'-scoped
// SolrQueryParser functionality
static final class SolrQueryParserDelegate extends SolrQueryParser {
private SolrQueryParserDelegate(QParser parser, String defaultField) {
super(parser, defaultField);
Expand All @@ -76,6 +78,11 @@ protected org.apache.lucene.search.Query getWildcardQuery(String field, String t
return super.getWildcardQuery(field, termStr);
}

@Override
protected Query getPrefixQuery(String field, String termStr) throws SyntaxError {
return super.getPrefixQuery(field, termStr);
}

@Override
protected org.apache.lucene.search.Query getRangeQuery(
String field, String part1, String part2, boolean startInclusive, boolean endInclusive)
Expand Down Expand Up @@ -135,12 +142,21 @@ protected Query newWildcardQuery(org.apache.lucene.index.Term t) {
}
}

/*
* SolrQueryParser is used to create the prefix query so that schema-aware logic
* and sanity checks (such as the "minimum prefix length") can be enforced.
*
* NOTE: This changes isn't viable, as it breaks some type assumptions made by
* ComplexPhraseQueryParser on the Lucene side. See 'instanceof' checks there, or
* run 'TestComplexPhraseQParserPlugin' for some examples.
*/
@Override
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
final var query = super.getPrefixQuery(field, termStr);
QueryUtils.ensurePrefixQueryObeysMinimumPrefixLength(
qParserReference, query, termStr);
return query;
protected Query getPrefixQuery(String field, String termStr) {
try {
return reverseAwareParser.getPrefixQuery(field, termStr);
} catch (SyntaxError e) {
throw new RuntimeException(e);
}
}

private Query setRewriteMethod(org.apache.lucene.search.Query query) {
Expand Down

0 comments on commit df18b2b

Please sign in to comment.