Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (23 sloc) 1.52 KB

Querying: Intersection

To allow users to Intersect queries on the server-side and return only documents that match all the provided sub-queries, we introduced the query intersection feature.

Let's consider a case where we have a T-Shirt class:

{CODE intersection_1@Indexes\Querying\Intersection.cs /}

We will fill our database with few records:

{CODE intersection_3@Indexes\Querying\Intersection.cs /}

Now we want to return all the T-shirts that are manufactured by Raven and contain both Small Blue and Large Gray types.

To do this, we need to do the following:

  • add the Raven.Client.Documents namespace to usings
  • use the Intersect query extension:

{CODE-TABS} {CODE-TAB:csharp:Query intersection_4@Indexes\Querying\Intersection.cs /} {CODE-TAB:csharp:DocumentQuery intersection_5@Indexes\Querying\Intersection.cs /} {CODE-TAB:csharp:Index intersection_2@Indexes\Querying\Intersection.cs /} {CODE-TAB-BLOCK:sql:RQL} from index 'TShirts/ByManufacturerColorSizeAndReleaseYear' where intersect(Manufacturer = 'Raven', Color = 'Blue' and Size = 'Small', Color = 'Gray' and Size = 'Large') {CODE-TAB-BLOCK/} {CODE-TABS/}

The above query will return tshirts/1 and tshirts/4 as a result. The document tshirts/2 will not be included because it is not manufactured by Raven, and tshirts/3 is not available in Small Blue so it does not match all the sub-queries.

Related Articles

Client API

You can’t perform that action at this time.