Using Intersect

To return only documents that match all provided sub-queries, use the intersect method which enables RavenDB to perform server-side intersection queries.

Syntax

def intersect(self) -> DocumentQuery[_T]: ...

Example

# return all T-shirts that are manufactured by 'Raven'
# and contain both 'Small Blue' and 'Large Gray' types
tshirts = list(
    session.query_index("TShirts/ByManufacturerColorSizeAndReleaseYear")
    .where_equals("manufacturer", "Raven")
    .intersect()
    .where_equals("color", "Blue")
    .and_also()
    .where_equals("size", "Small")
    .intersect()
    .where_equals("color", "Gray")
    .and_also()
    .where_equals("size", "Large")
    .of_type(TShirt)
)
class TShirts_ByManufacturerColorSizeAndReleaseYear(AbstractIndexCreationTask):
    class Result:
        def __init__(self, manufacturer: str = None, color: str = None, size: str = None, release_year: int = None):
            self.manufacturer = manufacturer
            self.color = color
            self.size = size
            self.release_year = release_year

    def __init__(self):
        super().__init__()
        self.map = (
            "from t in docs.TShirts from type in t.types select new {"
            " manufacturer = t.manufacturer,"
            " color = type.color,"
            " size = type.size,"
            " release_year = t.release_year"
            "}"
        )
from index 'TShirts/ByManufacturerColorSizeAndReleaseYear' 
where intersect(Manufacturer = 'Raven', Color = 'Blue' and Size = 'Small', Color = 'Gray' and Size = 'Large')