Lucene - Core
  1. Lucene - Core
  2. LUCENE-5344

Flexible StandardQueryParser behaves differently than ClassicQueryParser

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.5
    • Fix Version/s: 4.6.1, 4.7, 5.0
    • Component/s: core/queryparser
    • Labels:
      None

      Description

      AnalyzerQueryNodeProcessor creates a BooleanQueryNode instead of a MultiPhraseQueryNode for some circumstances.

      Classic query parser output: +content:a +content:320 (correct)

      QueryParser classicQueryParser;
      classicQueryParser = new QueryParser(Version.LUCENE_45, "content", anaylzer);
      classicQueryParser.setDefaultOperator(Operator.AND);
      classicQueryParser.parse("a320"));
      

      Flexible query parser output: content:a content:320 (wrong)

      StandardQueryParser flexibleQueryParser;
      flexibleQueryParser = new StandardQueryParser(anaylzer);
      flexibleQueryParser.setDefaultOperator(Operator.AND);
      flexibleQueryParser.parse("a320", "content"));
      

      The used analyzer:

      Analyzer anaylzer = return new Analyzer() {
        protected TokenStreamComponents createComponents(String field, Reader in) {
        Tokenizer   src = new WhitespaceTokenizer(Version.LUCENE_45, in);
        TokenStream tok = new WordDelimiterFilter(src,
           WordDelimiterFilter.SPLIT_ON_NUMERICS |
           WordDelimiterFilter.GENERATE_WORD_PARTS |
           WordDelimiterFilter.GENERATE_NUMBER_PARTS,
           CharArraySet.EMPTY_SET); 
        return new TokenStreamComponents(src, tok);
      };
      

        Activity

        Hide
        Krishna Keldec added a comment -

        As a workaround I have changed the following if-statement in AnalyzerQueryNode:

        } else if (severalTokensAtSamePosition || !(node instanceof QuotedFieldQueryNode)) {
          // changed || to &&
          if (positionCount == 1 && !(node instanceof QuotedFieldQueryNode)) {
          // no phrase query:      
        
        Show
        Krishna Keldec added a comment - As a workaround I have changed the following if-statement in AnalyzerQueryNode: } else if (severalTokensAtSamePosition || !(node instanceof QuotedFieldQueryNode)) { // changed || to && if (positionCount == 1 && !(node instanceof QuotedFieldQueryNode)) { // no phrase query:
        Hide
        Adriano Crestani added a comment -

        Thanks for reporting this bug Krishna. It was indeed behaving slightly different from the other QP.

        The attached file has the fix. I made sure to add a junit for the use case.

        I should apply it in a couple of days, if no one has any concerns.

        Show
        Adriano Crestani added a comment - Thanks for reporting this bug Krishna. It was indeed behaving slightly different from the other QP. The attached file has the fix. I made sure to add a junit for the use case. I should apply it in a couple of days, if no one has any concerns.
        Hide
        Adriano Crestani added a comment -

        Updating the previous patch (trunk). Adding a patch for branch 4x

        Show
        Adriano Crestani added a comment - Updating the previous patch (trunk). Adding a patch for branch 4x
        Hide
        ASF subversion and git services added a comment -

        Commit 1558305 from Adriano Crestani in branch 'dev/trunk'
        [ https://svn.apache.org/r1558305 ]

        LUCENE-5344 Flexible StandardQueryParser behaves differently than ClassicQueryParser

        Show
        ASF subversion and git services added a comment - Commit 1558305 from Adriano Crestani in branch 'dev/trunk' [ https://svn.apache.org/r1558305 ] LUCENE-5344 Flexible StandardQueryParser behaves differently than ClassicQueryParser
        Hide
        ASF subversion and git services added a comment -

        Commit 1558306 from Adriano Crestani in branch 'dev/branches/branch_4x'
        [ https://svn.apache.org/r1558306 ]

        LUCENE-5344 - Flexible StandardQueryParser behaves differently than ClassicQueryParser (branch 4x)

        Show
        ASF subversion and git services added a comment - Commit 1558306 from Adriano Crestani in branch 'dev/branches/branch_4x' [ https://svn.apache.org/r1558306 ] LUCENE-5344 - Flexible StandardQueryParser behaves differently than ClassicQueryParser (branch 4x)
        Hide
        Adriano Crestani added a comment -

        Committed at r1558305 (trunk) and r1558306 (branch 4x).

        Show
        Adriano Crestani added a comment - Committed at r1558305 (trunk) and r1558306 (branch 4x).
        Hide
        Michael McCandless added a comment -

        It looks like there's no CHANGES entry for this on trunk?

        I only noticed because I hit unexpected conflicts when merging another issue back to 4.x...

        Show
        Michael McCandless added a comment - It looks like there's no CHANGES entry for this on trunk? I only noticed because I hit unexpected conflicts when merging another issue back to 4.x...
        Hide
        ASF subversion and git services added a comment -

        Commit 1558693 from Adriano Crestani in branch 'dev/trunk'
        [ https://svn.apache.org/r1558693 ]

        LUCENE-5344: adding the change to CHANGES.txt

        Show
        ASF subversion and git services added a comment - Commit 1558693 from Adriano Crestani in branch 'dev/trunk' [ https://svn.apache.org/r1558693 ] LUCENE-5344 : adding the change to CHANGES.txt
        Hide
        Adriano Crestani added a comment -

        Good catch Michael! I had the change, I just missed it during the commit (not sure how).

        Show
        Adriano Crestani added a comment - Good catch Michael! I had the change, I just missed it during the commit (not sure how).

          People

          • Assignee:
            Adriano Crestani
            Reporter:
            Krishna Keldec
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development