[ https://issues.apache.org/jira/browse/LUCENE-9367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17242868#comment-17242868 ]
Zach Chen edited comment on LUCENE-9367 at 12/3/20, 2:37 AM: ------------------------------------------------------------- Looks like there's some inconsistency about parsing, as I can get *MatchNoDocsQuery* from *SimpleQueryParser* {code:java} public void test() throws IOException { Analyzer analyzer = CustomAnalyzer.builder() .withTokenizer(StandardTokenizerFactory.class) .addTokenFilter(StopFilterFactory.class) .build(); QueryBuilder queryBuilder = new QueryBuilder(analyzer); String onlyStopWords = "the and it"; Query query = queryBuilder.createPhraseQuery("AnyField", onlyStopWords); assertNull(query); query = new SimpleQueryParser(analyzer, "AnyField").parse(onlyStopWords); assertEquals(new MatchNoDocsQuery("empty string passed to query parser"), query); } {code} I can put out a PR to change it to MatchNoDocsQuery if that's the preferred direction? I also see additional changes though to check for MatchNoDocsQuery now instead of null in this situation. was (Author: zacharymorn): Looks like there's some inconsistency about parsing, as I can get *MatchNoDocsQuery* from *SimpleQueryParser* {code:java} public void test() throws IOException { Analyzer analyzer = CustomAnalyzer.builder() .withTokenizer(StandardTokenizerFactory.class) .addTokenFilter(StopFilterFactory.class) .build(); QueryBuilder queryBuilder = new QueryBuilder(analyzer); String onlyStopWords = "the and it"; Query query = queryBuilder.createPhraseQuery("AnyField", onlyStopWords); assertNull(query); query = new SimpleQueryParser(analyzer, "AnyField").parse(onlyStopWords); assertEquals(new MatchNoDocsQuery("empty string passed to query parser"), query); } {code} I can put out a PR to change it to MatchNoDocsQuery if that's the preferred direction? I also see additional changes though to check for MatchNoDocsQuery now instead of null in this situation. > Using a queryText which results in zero tokens causes a query to be built as > null > --------------------------------------------------------------------------------- > > Key: LUCENE-9367 > URL: https://issues.apache.org/jira/browse/LUCENE-9367 > Project: Lucene - Core > Issue Type: Bug > Components: core/search > Affects Versions: 7.2.1 > Reporter: Tim Brier > Priority: Major > > If a queryText produces zero tokens after being processed by an Analyzer, > when you try to build a Query with it the result is null. > > The following code reproduces this bug: > {code:java} > public class LuceneBug { > public Query buildQuery() throws IOException { > Analyzer analyzer = CustomAnalyzer.builder() > .withTokenizer(StandardTokenizerFactory.class) > .addTokenFilter(StopFilterFactory.class) > .build(); > QueryBuilder queryBuilder = new QueryBuilder(analyzer); > String onlyStopWords = "the and it"; > return queryBuilder.createPhraseQuery("AnyField", onlyStopWords); > } > } > {code} > -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org