boolean operators in querystring

183 views
Skip to first unread message

balazs

unread,
Jun 25, 2012, 1:39:10 PM6/25/12
to rav...@googlegroups.com
How do I handle boolean operators in the querystring?  For example:
CaseHTMLIndex?query=CaseHtml:\[x%20AND%20y\]&start=0&pageSize=10 and CaseHTMLIndex?query=CaseHtml:\[xANDy\]&start=0&pageSize=10 both come back with no results,
but:
CaseHTMLIndex?query=CaseHtml:\[x%20&&%20y\]&start=0&pageSize=10 and CaseHTMLIndex?query=CaseHtml:\[x&&y\]&start=0&pageSize=10 both do have results.  However, I'm not sure if those results are the result of correctly processing the boolean condition.

So, do AND and OR not work in the querystring, and should I rely on && and || instead?

balazs

unread,
Jun 25, 2012, 1:53:41 PM6/25/12
to rav...@googlegroups.com
It seems that while && and || do return results, they are incorrect.  So, how do I issue a boolean query using the HTTP API?

Oren Eini (Ayende Rahien)

unread,
Jun 25, 2012, 1:59:53 PM6/25/12
to rav...@googlegroups.com
AND and OR are case sensitive keywords

balazs

unread,
Jun 25, 2012, 2:05:47 PM6/25/12
to rav...@googlegroups.com
I realize that.  I am trying to search for all documents within the CaseHtml field that contain x and also contain y.  I was under the impression that translated to CaseHtml:[x AND y] or  CaseHtml:[x && y] both of which should work according to the Lucene documentation.  Is there some reason these are incorrect?  Also, how should these be encoded in the URL? 

Oren Eini (Ayende Rahien)

unread,
Jun 25, 2012, 2:15:58 PM6/25/12
to rav...@googlegroups.com
No, it does NOT work like that
What you are trying is not a supported syntax.

You want:

CaseHtml:x AND CaseHtml:y

Assuming that CaseHtml is an analyzed field.

balazs

unread,
Jun 25, 2012, 2:22:40 PM6/25/12
to rav...@googlegroups.com
Ah, I didn't realize that.  The RavenDB website says "You can pass any valid Lucene query...", and FieldName[conditions] is a valid Lucene query per Lucene's site:  http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Field Grouping .

So does this mean that if I want to issue a query for 10 different terms in a particular field, I need to parse it out into ten separate Field:condition statements?  That would be painful.

Also, is the field grouping supported by Advanced.LuceneQuery() using the client API or do I need to split out each condition there as well?

Oren Eini (Ayende Rahien)

unread,
Jun 25, 2012, 2:27:59 PM6/25/12
to rav...@googlegroups.com
No, it is NOT a valid query.

CaseHtml:(x OR y)

Would probably work, what you had was:

CaseHtml:[x OR y]

Note that [] vs ()

balazs

unread,
Jun 25, 2012, 2:36:57 PM6/25/12
to rav...@googlegroups.com
Ah, yes, that's true.  Sorry, that way a typo on my part.  Do you have any idea why I get the following results:
* ?query=FieldName:\(x%20AND %20 y\) = no results (should be 3)
*  ?query=FieldName:\(x%20&&%20y\) = 9 results (should be 3)
*  ?query=FieldName:\(x%20||%20y\) = 9 results (correct)
*  ?query=FieldName:\(x%20OR%20y\) = 9 results (correct) 

Is this some sort of encoding issue?

balazs

unread,
Jun 25, 2012, 3:24:27 PM6/25/12
to rav...@googlegroups.com
Alright, this was a silly issue: the problem was the leading \ before the ( and ) characters.  So, a correct version of the querystring should look like this:
?query=FieldName:(x%20AND%20y) 

Itamar Syn-Hershko

unread,
Jun 25, 2012, 2:57:49 PM6/25/12
to rav...@googlegroups.com
As Oren said, the && and || operators are meaningless here

Don't escape the parenthesis.
Reply all
Reply to author
Forward
0 new messages