Saturday, June 25, 2016

Weird behavior of Lucene query parser 5.1.0

Leave a Comment

I am using Lucene Query Parser 5.1.0

These filter queries do not work:

* AND {!tag=guid}guid:(*) * && {!tag=guid}guid:(*) * {!tag=guid}guid:(*) 

it throws

org.apache.solr.search.SyntaxError: Cannot parse 'guid:(*': Encountered \"<EOF>\" at line 1, column 7.\nWas expecting one of:\n <AND> ...\n <OR> ...\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \")\" ...\n \"*\" ...\n \"^\" ...\n <QUOTED> ...\n <TERM> ...\n <FUZZY_SLOP> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <LPARAMS> ...\n <NUMBER> ...\n

And these filter queries do work:

* AND {!tag=guid}guid:* * AND guid:(*) * AND guid:* * && {!tag=guid}guid:* * && guid:(*) * && guid:* * {!tag=guid}guid:* * guid:(*) * guid:* {!tag=guid}guid:(*) {!tag=guid}guid:* guid:(*) guid:* 

Why the first three do not work? Is it a bug in the query parser?

EDIT: I have found weird behavior also with spaces:

This does work:

* AND {!tag=guid}guid:"a" 

This does not work:

* AND {!tag=guid}guid:"a " 

1 Answers

Answers 1

Tags in FilterQueries are just special kind of LocalParameter used as reference point for faceting in SOLR.

Note that LocalParameters are SOLR specific and are not parsed in any meaningfull way with LuceneQueryParser.

If you are interested in general LocalParameter syntax, you can check:

https://cwiki.apache.org/confluence/display/solr/Local+Parameters+in+Queries

According to that document

Local parameters are arguments in a Solr request that are specific to a query parameter.

and

Basic Syntax of Local Parameters:

To specify a local parameter, insert the following before the argument to be modified:

  • Begin with {!
  • Insert any number of key=value pairs separated by white space
  • End with } and immediately follow with the query argument

You may specify only one local parameters prefix per argument.

You shouldn't therefore prefix Local Parameters with any parts of query as you do. If you really need to use multiple LocalParameters consider splitting big FilterQuery to multiple smaller ones using CNF


Additional usefull resource: https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/search/QParser.java

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment