1

Why is there a OR instead of an AND between the SEARCH and the WHERE?

The problem is that the current Lucene query is:

"OrganizationType:Boo ( Name:(Foo) ShortName:(Foo))"

instead of:

"OrganizationType:Boo AND ( Name:(Foo) ShortName:(Foo))"

How can I change that?

RavenQueryStatistics stats;
var organizationQuery = session.Query<Organization>()
                               .Statistics(out stats)
                               .Skip((request.Page - 1) * request.PageSize)
                               .Take(request.PageSize);

if (request.OrganizationType != default(OrganizationType))
{
    organizationQuery = organizationQuery.Where(o => o.OrganizationType == request.OrganizationType);
}

if (!string.IsNullOrEmpty(request.Query))
{
    organizationQuery = organizationQuery
                                         .Search(c => c.Name, request.Query, escapeQueryOptions: EscapeQueryOptions.AllowPostfixWildcard)
                                         .Search(c => c.ShortName, request.Query, escapeQueryOptions: EscapeQueryOptions.AllowPostfixWildcard);
}

I have added a screenshot with the proposed solution: enter image description here

Daniel Gartmann
  • 11,678
  • 12
  • 45
  • 60

2 Answers2

1

To get only documents matching all sub-queries you to have to use Intersect. See the article How to use intersect in the RavenDB documentation.

Thomas Freudenberg
  • 5,048
  • 1
  • 35
  • 44
1

Because Search is using OR by default. There is an optional parameter that set it to use AND.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Sorry maybe I wasn't clear enough. My problem is not the OR between the search but that the lucene query is "OrganizationType:Club ( Name:(F*) ShortName:(F*))" instead of "OrganizationType:Club AND ( Name:(F*) ShortName:(F*))". How can I achieve that? – Daniel Gartmann Feb 18 '15 at 22:04
  • Use the overload for the Search that tell it to use an AND – Ayende Rahien Feb 20 '15 at 08:31
  • I tried out with the SearchOptions.And and the Lucene query is: "OrganizationType:Club ( AND Name:(liv*) ShortName:(liv*))" and I get an aggregate exception. I have added a screenshot below the question in order to illustrate it. – Daniel Gartmann Feb 20 '15 at 14:21