Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-8287

ContextQuery with empty RegexCompletionQuery produces an assertion failure

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 7.4, 8.0
    • None
    • None
    • New

    Description

      When an empty RegexCompletionQuery is provided to ContextQuery, the following assertion failure occurs:

      java.lang.AssertionError: input should not end with the context separator
      at org.apache.lucene.search.suggest.document.ContextQuery$ContextCompletionWeight.setInnerWeight(ContextQuery.java:296)
      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.testEmptyRegexQuery(TestContextQuery.java:193)
      

      This is a bit of an edge case, but may be concerning since without assertions enabled, you can go on to access IntsRef indices that are out of bounds.

      The attached patch provides a reproduction of the issue, as the test case TestContextQuery#testEmptyRegexQuery. Note that 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#testEmptyRegexQuery). In this case, there is no error, and all suggestions are returned. 

      Attachments

        1. LUCENE-8287.patch
          2 kB
          Julie Tibshirani
        2. LUCENE-8287-repro.patch
          3 kB
          Julie Tibshirani

        Activity

          People

            Unassigned Unassigned
            jtibshirani Julie Tibshirani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 10m
                1h 10m