# Sorting
URL: /docs/sorting

Order search results by field values or by relevance.



The `sort` search parameter takes a comma-separated list of `field:direction`
clauses, evaluated left to right — later clauses break ties from earlier
ones:

```
sort=_text_match:desc,price:asc
```

* Each clause needs an explicit direction (`asc` or `desc`) — there's no
  default direction to omit.
* Only fields declared `sort: true` can be used.
* `_text_match` is a special pseudo-field for BM25 relevance — not a real
  field on your documents, but always available as a sort key.
* If two documents tie on every clause (or `sort` is omitted and no
  `default_sorting_field` applies), ties break on document `id`.

## Examples [#examples]

Cheapest first:

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl 'localhost:8108/collections/products/search?q=keyboard&sort=price:asc'
    ```
  </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: 'keyboard', sort: 'price:asc' });
    ```
  </Tab>

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

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

    results = client.collection("products").search(q="keyboard", sort="price:asc")
    ```
  </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 = "keyboard", Sort = "price:asc" });
    ```
  </Tab>
</Tabs>

Most relevant first, then cheapest as a tiebreaker:

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl 'localhost:8108/collections/products/search?q=keyboard&sort=_text_match:desc,price:asc'
    ```
  </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: 'keyboard',
      sort: '_text_match:desc,price:asc',
    });
    ```
  </Tab>

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

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

    results = client.collection("products").search(q="keyboard", sort="_text_match:desc,price:asc")
    ```
  </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 = "keyboard",
        Sort = "_text_match:desc,price:asc",
    });
    ```
  </Tab>
</Tabs>
