Lucene - Core
  1. Lucene - Core
  2. LUCENE-2458

queryparser makes all CJK queries phrase queries regardless of analyzer

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1, 4.0-ALPHA
    • Component/s: core/queryparser
    • Labels:
      None
    • Lucene Fields:
      New, Patch Available

      Description

      The queryparser automatically makes ALL CJK, Thai, Lao, Myanmar, Tibetan, ... queries into phrase queries, even though you didn't ask for one, and there isn't a way to turn this off.

      This completely breaks lucene for these languages, as it treats all queries like 'grep'.

      Example: if you query for f:abcd with standardanalyzer, where a,b,c,d are chinese characters, you get a phrasequery of "a b c d". if you use cjk analyzer, its no better, its a phrasequery of "ab bc cd", and if you use smartchinese analyzer, you get a phrasequery like "ab cd". But the user didn't ask for one, and they cannot turn it off.

      The reason is that the code to form phrase queries is not internationally appropriate and assumes whitespace tokenization. If more than one token comes out of whitespace delimited text, its automatically a phrase query no matter what.

      The proposed patch fixes the core queryparser (with all backwards compat kept) to only form phrase queries when the double quote operator is used.

      Implementing subclasses can always extend the QP and auto-generate whatever kind of queries they want that might completely break search for languages they don't care about, but core general-purpose QPs should be language independent.

      1. LUCENE-2458.patch
        24 kB
        Robert Muir
      2. LUCENE-2458.patch
        33 kB
        Robert Muir
      3. LUCENE-2458.patch
        57 kB
        Robert Muir
      4. LUCENE-2458.patch
        62 kB
        Robert Muir

        Issue Links

          Activity

          Robert Muir created issue -
          Robert Muir made changes -
          Field Original Value New Value
          Attachment LUCENE-2458.patch [ 12445136 ]
          Robert Muir made changes -
          Assignee Robert Muir [ rcmuir ]
          Robert Muir made changes -
          Fix Version/s 3.1 [ 12314822 ]
          Fix Version/s 4.0 [ 12314025 ]
          Lucene Fields [New] [New, Patch Available]
          Robert Muir made changes -
          Attachment LUCENE-2458.patch [ 12445208 ]
          Robert Muir made changes -
          Priority Critical [ 2 ] Blocker [ 1 ]
          Robert Muir made changes -
          Attachment LUCENE-2458.patch [ 12445369 ]
          Robert Muir made changes -
          Summary queryparser shouldn't generate phrasequeries based on term count queryparser makes all CJK queries phrase queries regardless of analyzer
          Description The current method in the queryparser to generate phrasequeries is wrong:

          The Query Syntax documentation (http://lucene.apache.org/java/3_0_1/queryparsersyntax.html) states:
          {noformat}
          A Phrase is a group of words surrounded by double quotes such as "hello dolly".
          {noformat}

          But as we know, this isn't actually true.

          Instead the terms are first divided on whitespace, then the analyzer term count is used as some sort of "heuristic" to determine if its a phrase query or not.
          This assumption is a disaster for languages that don't use whitespace separation: CJK, compounding European languages like German, Finnish, etc. It also
          makes it difficult for people to use n-gram analysis techniques. In these cases you get bad relevance (MAP improves nearly *10x* if you use a PositionFilter at query-time to "turn this off" for chinese).

          For even english, this undocumented behavior is bad. Perhaps in some cases its being abused as some heuristic to "second guess" the tokenizer and piece back things it shouldn't have split, but for large collections, doing things like generating phrasequeries because StandardTokenizer split a compound on a dash can cause serious performance problems. Instead people should analyze their text with the appropriate methods, and QueryParser should only generate phrase queries when the syntax asks for one.

          The PositionFilter in contrib can be seen as a workaround, but its pretty obscure and people are not familiar with it. The result is we have bad out-of-box behavior for many languages, and bad performance for others on some inputs.

          I propose instead that we change the grammar to actually look for double quotes to determine when to generate a phrase query, consistent with the documentation.
          The queryparser automatically makes *ALL* CJK, Thai, Lao, Myanmar, Tibetan, ... queries into phrase queries, even though you didn't ask for one, and there isn't a way to turn this off.

          This completely breaks lucene for these languages, as it treats all queries like 'grep'.

          Example: if you query for f:abcd with standardanalyzer, where a,b,c,d are chinese characters, you get a phrasequery of "a b c d". if you use cjk analyzer, its no better, its a phrasequery of "ab bc cd", and if you use smartchinese analyzer, you get a phrasequery like "ab cd". But the user didn't ask for one, and they cannot turn it off.

          The reason is that the code to form phrase queries is not internationally appropriate and assumes whitespace tokenization. If more than one token comes out of whitespace delimited text, its automatically a phrase query no matter what.

          The proposed patch fixes the core queryparser (with all backwards compat kept) to only form phrase queries when the double quote operator is used.

          Implementing subclasses can always extend the QP and auto-generate whatever kind of queries they want that might completely break search for languages they don't care about, but core general-purpose QPs should be language independent.
          Robert Muir made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Mark Miller made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Robert Muir made changes -
          Attachment LUCENE-2458.patch [ 12445937 ]
          Robert Muir made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Mark Thomas made changes -
          Workflow jira [ 12510653 ] Default workflow, editable Closed status [ 12564263 ]
          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12564263 ] jira [ 12584082 ]
          Grant Ingersoll made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Uwe Schindler made changes -
          Link This issue breaks SOLR-2493 [ SOLR-2493 ]

            People

            • Assignee:
              Robert Muir
              Reporter:
              Robert Muir
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development