Lucene - Core
  1. Lucene - Core
  2. LUCENE-337

Combination of BooleanQuery and PhrasePrefixQuery can provoke UnsupportedOperationException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: None
    • Component/s: core/search
    • Labels:
      None
    • Environment:

      Operating System: Mac OS X 10.3
      Platform: All

      Description

      A BooleanQuery including a PhrasePrefixQuery can cause an exception to be thrown
      from BooleanScorer#skipTo when the search is executed:

      java.lang.UnsupportedOperationException
      at org.apache.lucene.search.BooleanScorer.skipTo(BooleanScorer.java:189)
      at org.apache.lucene.search.ConjunctionScorer.doNext(ConjunctionScorer.java:53)
      at org.apache.lucene.search.ConjunctionScorer.next(ConjunctionScorer.java:48)
      at org.apache.lucene.search.Scorer.score(Scorer.java:37)
      at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:92)
      at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:64)
      at org.apache.lucene.search.Hits.<init>(Hits.java:43)
      at org.apache.lucene.search.Searcher.search(Searcher.java:33)
      at org.apache.lucene.search.Searcher.search(Searcher.java:27)
      ... (non-lucene code)

      The problem appears to be that PhrasePrefixQuery optimizes itself into a
      BooleanQuery when it contains only one term. However, it does this in the
      createWeight() method of its scorer instead of in the rewrite method of the
      query itself. Thus it bypasses the boolean typecheck when BooleanQuery is
      deciding whether to use ConjunctionScorer or BooleanScorer, eventually resulting
      in the UOE.

        Activity

        Hide
        Daniel Naber added a comment -

        Thanks, I committed your patch and the testcase to our CVS.

        Show
        Daniel Naber added a comment - Thanks, I committed your patch and the testcase to our CVS.
        Hide
        Rhett Sutphin added a comment -

        Here's the stacktrace I get when running that test without the fix in place:

        java.lang.UnsupportedOperationException
        at org.apache.lucene.search.BooleanScorer.skipTo(BooleanScorer.java:189)
        at org.apache.lucene.search.ConjunctionScorer.doNext(ConjunctionScorer.java:53)
        at org.apache.lucene.search.ConjunctionScorer.next(ConjunctionScorer.java:48)
        at org.apache.lucene.search.Scorer.score(Scorer.java:37)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:92)
        at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:64)
        at org.apache.lucene.search.Hits.<init>(Hits.java:43)
        at org.apache.lucene.search.Searcher.search(Searcher.java:33)
        at org.apache.lucene.search.Searcher.search(Searcher.java:27)
        at
        org.apache.lucene.search.TestBooleanQueryContainingPhrasePrefixQueries.testBooleanQueryContainingSingleTermPrefixQuery(TestBooleanQueryContainingPhrasePrefixQueries.java:57)

        Show
        Rhett Sutphin added a comment - Here's the stacktrace I get when running that test without the fix in place: java.lang.UnsupportedOperationException at org.apache.lucene.search.BooleanScorer.skipTo(BooleanScorer.java:189) at org.apache.lucene.search.ConjunctionScorer.doNext(ConjunctionScorer.java:53) at org.apache.lucene.search.ConjunctionScorer.next(ConjunctionScorer.java:48) at org.apache.lucene.search.Scorer.score(Scorer.java:37) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:92) at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:64) at org.apache.lucene.search.Hits.<init>(Hits.java:43) at org.apache.lucene.search.Searcher.search(Searcher.java:33) at org.apache.lucene.search.Searcher.search(Searcher.java:27) at org.apache.lucene.search.TestBooleanQueryContainingPhrasePrefixQueries.testBooleanQueryContainingSingleTermPrefixQuery(TestBooleanQueryContainingPhrasePrefixQueries.java:57)
        Hide
        Rhett Sutphin added a comment -

        Created an attachment (id=14045)
        A testcase that demonstrates the bug

        Show
        Rhett Sutphin added a comment - Created an attachment (id=14045) A testcase that demonstrates the bug
        Hide
        Daniel Naber added a comment -

        Thank you – could you also attach a test case or a code snippet that triggers
        the problem?

        Show
        Daniel Naber added a comment - Thank you – could you also attach a test case or a code snippet that triggers the problem?
        Hide
        Rhett Sutphin added a comment -

        Created an attachment (id=14044)
        Patch to optimize in rewrite instead of createWeight

        This patch moves the optimization from createWeight to rewrite. This patch is
        against the current CVS even though my initial bug report was against the 1.4.3
        release.

        Show
        Rhett Sutphin added a comment - Created an attachment (id=14044) Patch to optimize in rewrite instead of createWeight This patch moves the optimization from createWeight to rewrite. This patch is against the current CVS even though my initial bug report was against the 1.4.3 release.

          People

          • Assignee:
            Lucene Developers
            Reporter:
            Rhett Sutphin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development