apache / apache/lucene

Context query with regex "." produces an assertion failure [LUCENE-8288]

Open
#9,335 3 comments 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Major type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

When a RegexCompletionQuery of "." is provided to ContextQuery, the following assertion failure occurs:

```java
java.lang.AssertionError: input should not end with a context separator followed by SEP_LABEL

at org.apache.lucene.search.suggest.document.ContextQuery$ContextCompletionWeight.setInnerWeight(ContextQuery.java:299)
at org.apache.lucene.search.suggest.document.ContextQuery$ContextCompletionWeight.setNextMatch(ContextQuery.java:275)
at org.apache.lucene.search.suggest.document.NRTSuggester.lookup(NRTSuggester.java:221)
at org.apache.lucene.search.suggest.document.CompletionScorer.score(CompletionScorer.java:70)
at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:39)
at org.apache.lucene.search.suggest.document.SuggestIndexSearcher.suggest(SuggestIndexSearcher.java:78)
at org.apache.lucene.search.suggest.document.SuggestIndexSearcher.suggest(SuggestIndexSearcher.java:58)
at org.apache.lucene.search.suggest.document.TestContextQuery.testDotRegexQuery(TestContextQuery.java:188)
```

Note that this is a related, but distinct issue from #9334, where the RegexCompletionQuery is empty.

The attached patch provides a reproduction of the issue, as the test case TestContextQuery#testRegexDotQuery. To reproduce, Java assertions must be enabled (as in the default configuration for tests).

The patch also provides a test case for the normal behavior of an empty RegexCompletionQuery, when it is not wrapped in ContextQuery (TestRegexCompletionQuery#testRegexDotQuery). In this case, there is no error, and all suggestions are returned.

From a quick look, it seems as though "." doesn't capture any characters past  CompletionAnalyzer.SEP_LABEL, so the matching prefix in ContextCompletionWeight#setInnerWeight is unexpectedly empty.

---
Migrated from [LUCENE-8288](https://issues.apache.org/jira/browse/LUCENE-8288) by Julie Tibshirani (@jtibshirani), updated May 07 2018
Attachments: [LUCENE-8288.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8288/LUCENE-8288.patch) (versions: 2), [LUCENE-8288-repro.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8288/LUCENE-8288-repro.patch)

Contributor guide

Open the contributing guide

Research direction

Start with TestContextQuery#testDotRegexQuery and reproduce the failure with Java assertions enabled. Read ContextQuery$ContextCompletionWeight#setInnerWeight and the related ContextQuery and NRTSuggester stack locations, then compare TestRegexCompletionQuery#testDotRegexQuery. Done means the ContextQuery case no longer asserts while the standalone regex test still returns all suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.