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

Combination of BooleanQuery and PhrasePrefixQuery can provoke UnsupportedOperationException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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

    • Bugzilla Id:
      33161

      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
        rhett@detailedbalance.net 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@detailedbalance.net 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.
        Hide
        daniel.naber@t-online.de 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@t-online.de Daniel Naber added a comment - Thank you – could you also attach a test case or a code snippet that triggers the problem?
        Hide
        rhett@detailedbalance.net Rhett Sutphin added a comment -

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

        Show
        rhett@detailedbalance.net Rhett Sutphin added a comment - Created an attachment (id=14045) A testcase that demonstrates the bug
        Hide
        rhett@detailedbalance.net 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@detailedbalance.net 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
        daniel.naber@t-online.de Daniel Naber added a comment -

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

        Show
        daniel.naber@t-online.de Daniel Naber added a comment - Thanks, I committed your patch and the testcase to our CVS.

          People

          • Assignee:
            java-dev@lucene.apache.org Lucene Developers
            Reporter:
            rhett@detailedbalance.net Rhett Sutphin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development