How to order Wheres and Searches to get desired lucene boolean expression?

29 views
Skip to first unread message

Josh Buedel

unread,
Aug 23, 2017, 5:15:48 PM8/23/17
to RavenDB - 2nd generation document database

My C# Where calls translates to this lucene, which is what I want. That is, they are all AND'ed together.

 

{(Tenant:TEST) AND (Category:Cats) AND (SubCategory:Motorcycle) AND (OwningCatalogId:2)}

 

When I add in two Search terms I get this:

 

                {(Tenant:TEST) ( ProfileId:(8081) ProfileName:(*8081*)) AND (Category:Cats) AND (SubCategory:Motorcycle) AND (OwningCatalogId:2)}

 

Note that the Tenant term appears OR’ed into the others. It should be AND’ed. Like so:

 

                {(Tenant:TEST) AND ( ProfileId:(8081) ProfileName:(*8081*)) AND (Category:Cats) AND (SubCategory:Motorcycle) AND (OwningCatalogId:2)}

 

How do I order my search terms to achieve this?


I hope the answer isn't "move the Where(x => x.Tenant == "TEST") term after the Search(...) calls" because the query is constructed in a domain object that enforces a tenant restriction. The caller is free to append on further filtering, but I'd like to protect against forgetting that tenant term.

Oren Eini (Ayende Rahien)

unread,
Aug 24, 2017, 5:33:09 AM8/24/17
to ravendb
Search will OR by default, one of the optional parameters there is a SearchOperator that controls that.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Buedel

unread,
Aug 24, 2017, 10:26:23 AM8/24/17
to RavenDB - 2nd generation document database
Yes, I had experimented with those a bit but still couldn't get correct results. Specifically, getting the Search() terms to OR to each other, but ANDing that composite predicate in with all the others. I'll experiment a bit more today and come back with some examples.

Oren Eini (Ayende Rahien)

unread,
Aug 24, 2017, 3:38:42 PM8/24/17
to ravendb
You can put the searches together, so they are ORed, the add the last one with AND, IIRC

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Thu, Aug 24, 2017 at 5:26 PM, Josh Buedel <jbu...@gmail.com> wrote:
Yes, I had experimented with those a bit but still couldn't get correct results. Specifically, getting the Search() terms to OR to each other, but ANDing that composite predicate in with all the others. I'll experiment a bit more today and come back with some examples.

--
Reply all
Reply to author
Forward
0 new messages