solredismax

Why does Solr in the ExtendedDismaxQParser the keyword AND and OR are converted to question mark?


I found that when I run a Solr query like the below.

q:+fruit +"apple and banana"

The ExtendedDismaxQParser is converting it to the below. (Using the debugQuery flag I was able to see the conversion when going from querystring to parsedquery in the debug output.)

+fruit +"apple ? banana"

This obviously changes the query to match the words apple and banana with any word in between them. Not the expected behavior for a phrase in a query.

Is there a way to turn this behavior off so it respects the words AND and OR inside a phrase?

Below is a sanitized version of the JSON debug output.

"rawquerystring":"+(field1:\"apple and health\"^1 field2:\"apple and banana\"^5 field3:\"apple and banana\"^1)", "querystring":"+(field1:\"apple and banana\"^1 field2:\"apple and banana\"^5 field3:\"apple and banana\"^1)", "parsedquery":"(+(PhraseQuery(field1:\"apple ? banana\") PhraseQuery(field2:\"apple ? banana\"^5.0) PhraseQuery(field3:\"apple ? banana\")) (field2:[* TO *]^10.0 hasdescription:y^10.0) FunctionQuery((200.0/(2.0*float(div(ms(const(1499700124562),date(displaydate)),const(84000000)))+20.0))^7.0) FunctionQuery((float(erpm))^0.0) FunctionQuery((200.0/(2.0*float(geodist(latlon(latlong),39.8027,-86.1557))+20.0))^10.0))/no_coord", "parsedquery_toString":"+(field1:\"apple ? banana\" field2:\"apple ? banana\"^5.0 field3:\"apple ? banana\") (field2:[* TO *]^10.0 hasdescription:y^10.0) (200.0/(2.0*float(div(ms(const(1499700124562),date(displaydate)),const(84000000)))+20.0))^7.0 (float(erpm))^0.0 (200.0/(2.0*float(geodist(latlon(latlong),39.8027,-86.1557))+20.0))^10.0", "QParser":"ExtendedDismaxQParser",


Solution

  • Edismax have nothing to do with this. In your managed schema you must have configured StopFilterFactory filter and stopwords.txt contains and,or words.
    Because of this Filter solr will not indexed these words and you can not query afterwards. But solr keeps the position of words.
    Now in your case when you are searching for "apple and banana". Filter will replace and with question mark, So that words in your phrase will remain in order to match the content in solr.