Emmanuel Keller created LUCENE-7878:
---------------------------------------

             Summary: QueryParser AND default operator and MultiWords synonyms 
failed if keywords exactly matches a synonym
                 Key: LUCENE-7878
                 URL: https://issues.apache.org/jira/browse/LUCENE-7878
             Project: Lucene - Core
          Issue Type: Bug
          Components: core/queryparser
    Affects Versions: 6.5.1, 6.6, master (7.0)
         Environment: 1.8.0_131-b11 on Mac OS X
            Reporter: Emmanuel Keller


This issue is about using the QueryParser with MultiWordsSynonyms.

The reproduce the bug:
- Use AND as default operator
- Use a query string which exactly matches one synonym.

In short, the part of the query which handle the synonym lookup should keep a 
"OR" relation between the search synonyms, but it is translated as a "AND".

If I parse: "guinea pig" which is a synonym of "cavy":

Using default OR, I get something correct:
    "(+guinea +pig) cavy"

Note: I should probably better have ((+guinea +pic) cavy)

Using default AND, I get something wrong:
    +(+guinea +pig) +cavy

I was expected:
    +((+guinea +pig) +cavy)

To help understanding. If now I parse "guinea pig world"
And I get the expected result:
    +((+guinea +pig) cavy) +world

The relation between "guinea pig" and "cavy" is a OR as expected (it is a 
synonym), and the relation with "world" is AND as expected by the default 
operator.

Here is the additional unit test for, I hope it is pretty self-explanatory:
org.apache.lucene.queryparser.classic.TestQueryParser

{code:java}
public void testDefaultOperatorWhenKeywordsMatchesExactlyOneSynonym() throws 
ParseException {
    // Using the default OR operator
    QueryParser smart = new QueryParser("field", new Analyzer1());
    smart.setSplitOnWhitespace(false);
    smart.setDefaultOperator(Operator.OR);
    assertEquals("(+guinea +pig) cavy", smart.parse("guinea 
pig").toString("field"));

    // Using the default AND operator
    smart = new QueryParser("field", new Analyzer1());
    smart.setSplitOnWhitespace(false);
    smart.setDefaultOperator(Operator.AND);
    assertEquals("+((+guinea +pig) cavy) +cavy", smart.parse("guinea pig 
cavy").toString("field"));

    // Using the default AND operator
    smart = new QueryParser("field", new Analyzer1());
    smart.setSplitOnWhitespace(false);
    smart.setDefaultOperator(Operator.AND);
    assertEquals("+((+guinea +pig) cavy)", smart.parse("guinea 
pig").toString("field"));
  }
{code}




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to