jgr
jgr

Reputation: 2931

Dismax query parser and special values

In Solr documentaion i see that using dismax i can put query value from user as it is. https://cwiki.apache.org/confluence/display/solr/The+DisMax+Query+Parser

The DisMax query parser supports an extremely simplified subset of the Lucene QueryParser syntax. As in Lucene, quotes can be used to group phrases, and +/- can be used to denote mandatory and optional clauses. All other Lucene query parser special characters (except AND and OR) are escaped to simplify the user experience

So only those values have some special meanings: AND,NOT,+,-,"

But when i use NOT phrase it also behave like Boolean Operator. Also when i have query:

q:"Difference Java &&",

i get:

 "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.parser.ParseException"],
    "msg":"org.apache.solr.search.SyntaxError: Cannot parse 'Difference Java &&': Encountered \"<EOF>\" at line 1, column 18.\r\nWas expecting one of:\r\n    <NOT> ...\r\n    \"+\" ...\r\n    \"-\" ...\r\n    <BAREOPER> ...\r\n    \"(\" ...\r\n    \"*\" ...\r\n    <QUOTED> ...\r\n    <TERM> ...\r\n    <PREFIXTERM> ...\r\n    <WILDTERM> ...\r\n    <REGEXPTERM> ...\r\n    \"[\" ...\r\n    \"{\" ...\r\n    <LPARAMS> ...\r\n    \"filter(\" ...\r\n    <NUMBER> ...\r\n    <TERM> ...\r\n    \"*\" ...\r\n    ",
    "code":400}}

Did i misunderstand something or its documentation bug? Is there some easy way to ignore all lucene special characters and just put query phrase from user into dismax query? Standard tokenizer should anyway ingore those values (its ok for me)

Upvotes: 0

Views: 921

Answers (1)

Aman Tandon
Aman Tandon

Reputation: 1509

As mentioned, quotes can be used to group phrases, all you need to do is to escape the quotes.

Internally, it is using the double quotes and when you are passing the same it is breaking it. So escape it then it should work fine.

q:"Difference Java &&"

Moreover, I suppose you are using the && for boolean operators, so you need not to pass it inside the quotes

I am doing this query("java" && "python") on my local

Parser parses it correctly after encoding the &-> %26.

q="java"%20**%26%26**%20"python"&wt=json&debug=true&qf=creator_txt&defType=dismax

"parsedquery_toString":"+(+(creator_txt:java) +(creator_txt:python)) ()",

Upvotes: 0

Related Questions