apache / apache/lucene

Using a queryText which results in zero tokens causes a query to be built as null [LUCENE-9367]

Open
#10,407 2 comments 0 reactions 0 assignees View on GitHub
affects-version:7.2.1 legacy-jira-priority:Major module:core/search type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

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:

```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);
}
}
```

---
Migrated from [LUCENE-9367](https://issues.apache.org/jira/browse/LUCENE-9367) by Tim Brier, updated Dec 03 2020

Contributor guide

Open the contributing guide

Research direction

Start with the provided LuceneBug reproduction, focusing on QueryBuilder.createPhraseQuery and the CustomAnalyzer configuration using StandardTokenizerFactory and StopFilterFactory. Trace the zero-token case and determine the intended query result before adding a regression test that captures the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.