Hi,
I am looking at parsing boolean query strings as below :
condition 1 AND conditon2 OR condition3 NOT (condition 4 AND condition5 NOT condition6) AND condition7
Can someone suggest if there is already a boolean query parser that would break down the above query into tokens? Or I will have to manually break the above string into tokens?
Also BoolQueryBuilder class has MUST, MUST NOT and Should.
Can someone tell me the difference between MUST and SHOULD?
Hi Clint,
Thanks for your response
QueryStringQueryBuilder.Operator just has AND and OR operators. Would you
know how can one use NOT operator?
Thats the default operator for text analyzed in the query string. For
example: "green blue", will be broken down into "green AND blue" with AND
default operator, "green OR blue" with OR default operator. NOT does not
really make sense here.
Hi Kimchy,
Thanks for response.
We are looking at a scenario where user could enter the below sample query string :
condition 1 AND conditon2 OR condition3 NOT (condition 4 AND condition5 NOT condition6) AND condition7
In this case, do you recommend using QueryStringQuery or BoolQuery?
I depends a little on what your condition1-x actually are but I would think
you are best off using the QueryStringQuery. With that you do not have to
implement your own parsing (that would be required if you wanted to use the
lower level BoolQuery).
Thanks for the suggestion Jan. The condition could be something like field1=value1 AND field2=value2 OR field3=value3 NOT field4=value4
Also the QueryStringQueryBuilder.Operator class just has AND and OR. Not sure how we could implement the NOT condition (BoolQuery has MUST NOT)
The QueryStringBuilder supports the full Lucene query syntax (as Clinton
pointed out earlier): http://lucene.apache.org/java/3_4_0/queryparsersyntax.html
It therefore does support the NOT operator and also grouping logical
expressions via parenthesis. The only difference to the notation you are
looking for is how fields are accessed. In Lucene notation you would refer
to fields via something like 'field1:value1'.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.