Daniel Rabus created SOLR-18673:
-----------------------------------
Summary: eDisMax: An operator between "(" and a quoted phrase
becomes a literal term, so (-"x") matches x
Key: SOLR-18673
URL: https://issues.apache.org/jira/browse/SOLR-18673
Project: Solr
Issue Type: Bug
Components: query parsers
Affects Versions: 10.1
Reporter: Daniel Rabus
The eDisMax parser loses an operator that sits between an opening parenthesis
and a quoted phrase.
A negated phrase in parentheses then matches the documents that contain the
phrase. It should match the documents that do not contain the phrase. The same
happens to the exclamation mark operator before a quoted phrase, even without a
parenthesis. The standard Lucene parser handles all of these queries correctly.
h3. Steps to reproduce
# Start the {{techproducts}} example.
# Run each query below with the eDisMax parser and the request parameters
below.
# Run the same queries with {{{}defType=lucene{}}}.
# Compare the parsed queries in the debug output.
{noformat}
bin/solr start -e techproducts
defType=edismax&qf=id&debugQuery=true
{noformat}
Parsed queries (parsedquery_toString) on Solr 10.1.0:
{noformat}
q=-"x"
edismax: +(-(id:x) +*:*)^1.0
lucene: (-id:x +*:*)^1.0
q=(-x)
edismax: +(+(-(id:x) +*:*)^1.0)
lucene: +(-id:x +*:*)^1.0
q=(-"x")
edismax: +(+(+(id:-) +(id:x)))
lucene: +(-id:x +*:*)^1.0
q=( -"x")
edismax: +(+(-(id:x) +*:*)^1.0)
lucene: +(-id:x +*:*)^1.0
q=a (-"x" -"y")
edismax: +(+(id:a) +(+(id:-) +(id:x) -(id:y)))
lucene: +id:a +(-id:x -id:y +*:*)^1.0
q=!"x"
edismax: +(+(id:!) +(id:x))
lucene: (-id:x +*:*)^1.0
q=(NOT "x")
edismax: +(+(-(id:x) +*:*)^1.0)
lucene: +(-id:x +*:*)^1.0
{noformat}
h3. Actual result
For the query (-"x"), eDisMax creates a literal term that consists of the minus
sign.
It also creates a required clause for x.
On a text field, the analyzer removes the term with the minus sign.
The query then matches exactly the documents that it should exclude.
The plus sign and the exclamation mark before a quoted phrase show the same
pattern.
h3. Expected result
eDisMax parses these queries like the Lucene parser does.
The query (-"x") excludes x, like the query ( -"x") with a space after the
parenthesis.
The query !"x" excludes x, like the query NOT "x".
h3. Cause
{{ExtendedDismaxQParser.splitIntoClauses}} only recognizes the plus and minus
operators at the start of a clause.
In the query (-"x"), the clause starts with the parenthesis.
The bare-word loop ends the clause at the opening quote.
So the first clause is the parenthesis with the minus sign, and the phrase
becomes the next clause.
{{rebuildUserQuery}} joins the clauses with a space.
The query parser reads an operator followed by whitespace as a literal term.
The Lucene parser gives the same result for the rebuilt query:
{noformat}
q=(- "x")
lucene: +id:- +id:x
{noformat}
The exclamation mark fails the same way, because {{splitIntoClauses}} does not
detect it as an operator at the start of a clause.
h3. Fix
Possible approaches:
* Do not insert a space in {{rebuildUserQuery}} when a clause ended at an
opening quote.
* Or detect operators after leading parentheses in {{{}splitIntoClauses{}}},
as {{getFieldName}} already does for fielded queries (see SOLR-3377).
Workaround: put a space after the parenthesis, or use NOT instead of the minus
sign.
Related: SOLR-3377, SOLR-4480, SOLR-3744.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]