# Filtering
URL: /docs/filtering

Narrow search results with boolean expressions over structured fields.



The `filter` search parameter accepts a small boolean expression language
over fields declared `filter: true` (or `facet: true`/`sort: true` — any of
the three makes a field usable in a filter).

```
expr      := or
or        := and ( "||" and )*
and       := primary ( "&&" primary )*
primary   := "(" expr ")" | predicate
predicate := field ":" op? value
op        := "=" | "!=" | ">=" | "<=" | ">" | "<"
value     := "[" scalar ".." scalar "]"     range, inclusive
           | "[" scalar ("," scalar)* "]"   set membership
           | scalar
```

`&&` binds tighter than `||`. A bare `field:value` (no operator) means
equality. Strings can be bare, single-, or double-quoted.

## Examples [#examples]

```
brand:=Logitech && price:<5000
```

```
(brand:=Logitech || brand:=Razer) && price:[1000..5000]
```

```
brand:=[Logitech,Razer] && in_stock:=true
```

```
price:[100..500]
```

Ranges (`[a..b]`) are inclusive on both ends. Set membership (`[a,b,c]`)
matches if the field equals any listed value.

## In a search request [#in-a-search-request]

The filter expression is a plain string, passed through unmodified —
constructing it is on you (watch for injection if any part comes from user
input):

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl -G 'localhost:8108/collections/products/search' \
      --data-urlencode 'q=mouse' \
      --data-urlencode 'filter=brand:=Logitech && price:<5000'
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    import { Tachyon } from 'tachyon-sdk';

    const client = new Tachyon({ url: 'http://localhost:8108' });

    const results = await client.collection('products').search({
      q: 'mouse',
      filter: 'brand:=Logitech && price:<5000',
    });
    ```
  </Tab>

  <Tab value="Python">
    ```python
    from tachyon_sdk import Tachyon

    client = Tachyon(url="http://localhost:8108")

    results = client.collection("products").search(q="mouse", filter="brand:=Logitech && price:<5000")
    ```
  </Tab>

  <Tab value="C#">
    ```csharp
    using Tachyon.Sdk;

    var client = new TachyonClient(new TachyonClientOptions { Url = "http://localhost:8108" });

    var results = await client.Collection("products").SearchAsync(new SearchParams
    {
        Q = "mouse",
        Filter = "brand:=Logitech && price:<5000",
    });
    ```
  </Tab>
</Tabs>

## Notes [#notes]

* Using a field that isn't declared `filter`, `facet`, or `sort` returns a
  `400 invalid_query` error naming the field.
* `!=` excludes documents that have no value for the field at all, rather
  than treating a missing value as a non-match that could still pass.
* Filters don't affect ranking — they only narrow the candidate set before
  BM25 scoring runs.
