> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ticktock.bet/llms.txt
> Use this file to discover all available pages before exploring further.

# Unified Search

> Trigram-ranked free-text search across matches, teams, players, and tournaments

## What it returns

One flat, score-sorted list of mixed-type hits. Each item carries a `type` discriminator (`match` / `team` / `player` / `tournament`), the entity's stable id, a short `label` for the primary line, a `sub_label` for the secondary line, and a `score` between 0 and 1. Hits are intentionally lean — clients follow up with `GET /cs2/v1/{type}/{id}` when the user picks one.

Designed for global autocomplete bars: one round-trip per keystroke, no client-side merging across four list endpoints.

## Required scope

No single scope is required at the endpoint level. Instead, each **result type** is filtered by the matching list scope:

| Result type  | Required scope         |
| ------------ | ---------------------- |
| `match`      | `cs2:matches:list`     |
| `team`       | `cs2:teams:list`       |
| `player`     | `cs2:players:list`     |
| `tournament` | `cs2:tournaments:list` |

Missing a scope simply drops that type from the response — **no 403**. A key with zero list scopes gets an empty `data` array. This lets the same endpoint serve narrow-scope keys (e.g. team-only autocomplete) and broad operator keys without a distinct URL per audience.

## Ranking

Tiered relevance score over each entity's name column, taking the **max** across tiers:

| Tier                     | Match condition                | Score       |
| ------------------------ | ------------------------------ | ----------- |
| exact (case-insensitive) | `lower(name) = lower(q)`       | 1.00        |
| prefix                   | `name ILIKE 'q%'`              | 0.90        |
| substring                | `name ILIKE '%q%'`             | 0.70        |
| trigram similarity       | pg\_trgm `similarity(name, q)` | 0.00 – 1.00 |

Rows scoring below 0.15 are dropped. Trigram tier handles typos and partial words ("vitalty" → "Vitality", "naturl" → "Natural") via Postgres `pg_trgm` GIN indexes.

**Match search.** Matches don't carry their own name. They're scored via FK joins — a match's score is `max(team_a_score, team_b_score, tournament_score)`. Typing a team surfaces that team's upcoming/live/recent fixtures; typing a tournament surfaces all its matches.

## Behaviour notes

* **Minimum query length is 2 characters.** Single-char queries match too broadly to rank usefully and return `400`.
* **`limit` is the total across all types**, not a per-type cap. One result type can fill all slots when no others match.
* **`types=` is honoured first**, then scope-filtered. Asking for `types=teams,players` with a teams-only key returns teams; the unknown-to-this-key `players` type is silently dropped.
* **Stable ordering on ties.** Matches are passed in first, so when a team and a match tie on score, the match wins — fixtures are the most actionable autocomplete result.

## Examples

Autocomplete across everything:

```bash theme={null}
curl -H "X-API-Key: $TT_KEY" \
  "https://ticktock.bet/cs2/v1/search?q=vitality&limit=8"
```

Teams + players only, deeper result list:

```bash theme={null}
curl -H "X-API-Key: $TT_KEY" \
  "https://ticktock.bet/cs2/v1/search?q=zyw&types=teams,players&limit=20"
```

Find upcoming fixtures by tournament name:

```bash theme={null}
curl -H "X-API-Key: $TT_KEY" \
  "https://ticktock.bet/cs2/v1/search?q=blast+major&types=matches&limit=15"
```

## Related

* `GET /cs2/v1/teams?search=` — same ranking, scoped to teams, supports pagination and region filter.
* `GET /cs2/v1/players?search=` — same ranking, scoped to players, supports current-team filter.


## OpenAPI

````yaml openapi/cs2-api.json GET /cs2/v1/search
openapi: 3.1.0
info:
  title: TickTock B2B API
  description: >-
    Unified CS2 API (``/cs2/v1/*``) plus sport-agnostic ``/v1/*`` meta
    endpoints. Tenant-authenticated via ``X-API-Key`` or ``x-access-token``
    header (REST), or ``api_key`` query parameter (WebSocket). Field visibility
    is gated by per-key scopes — see ``docs/CS2_API_REFERENCE.md`` for the
    catalog and migration.
  version: 1.0.0
servers:
  - url: https://ticktock.bet
    description: Production (same-origin proxy)
  - url: https://feed.ticktock.bet
    description: Production (B2B subdomain)
security: []
paths:
  /cs2/v1/search:
    get:
      tags:
        - CS2
      summary: Unified CS2 search across matches, teams, players, tournaments
      description: >-
        Trigram-ranked free-text search. Results are merged into one list with a
        ``type`` discriminator (``team`` / ``player`` / ``tournament`` /
        ``match``) and sorted by relevance score. Useful for global autocomplete
        bars.


        **Scope behavior.** A result type is included only when the calling key
        holds the matching list scope (``cs2:matches:list``, ``cs2:teams:list``,
        ``cs2:players:list``, ``cs2:tournaments:list``). Missing scopes silently
        filter their type out — no 403. A key with zero list scopes gets an
        empty ``data`` array.


        **Ranking.** Exact match (1.0) > prefix match (0.9) > substring match
        (0.7) > trigram similarity (continuous). Results below 0.15 are dropped.


        **Match search.** Fixtures match when *any* of their anchored team or
        tournament names score above the floor — score = max(team_a, team_b,
        tournament).
      operationId: unified_search_cs2_v1_search_get
      parameters:
        - name: q
          in: query
          required: true
          schema:
            type: string
            minLength: 2
            description: Search query. Minimum 2 characters.
            title: Q
          description: Search query. Minimum 2 characters.
        - name: types
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              Comma-separated subset of ``matches,teams,players,tournaments``.
              Omitted → all four (subject to scope filtering).
            title: Types
          description: >-
            Comma-separated subset of ``matches,teams,players,tournaments``.
            Omitted → all four (subject to scope filtering).
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            maximum: 50
            minimum: 1
            description: Maximum results across all types combined.
            default: 10
            title: Limit
          description: Maximum results across all types combined.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                title: Response Unified Search Cs2 V1 Search Get
              example:
                data:
                  - type: team
                    id: 11712
                    label: Sashi
                    sub_label: 'EMEA · #42'
                    score: 1
                  - type: match
                    id: 52ef0d9c-7c1f-4c4e-9b3a-4a5e2f8b1c10
                    label: Sashi vs OG
                    sub_label: ESL Pro League S20 · live
                    score: 1
                  - type: player
                    id: 7998
                    label: s1mple
                    sub_label: Aleksandr Kostyliev
                    score: 0.68
                  - type: tournament
                    id: 7902
                    label: ESL Pro League S20
                    sub_label: 2026 · S-tier · LAN
                    score: 0.41
                meta:
                  count: 4
                  by_type:
                    team: 1
                    match: 1
                    player: 1
                    tournament: 1
                  types_searched:
                    - matches
                    - teams
                    - players
                    - tournaments
                  q: sashi
            application/xml: {}
        '401':
          description: >-
            Missing API key. Pass either `X-API-Key: <your-key>` or
            `$x$access-token: <your-key>` on REST calls (or `?api_key=` on
            WebSocket handshakes).
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: Human-readable error message.
                required:
                  - detail
              example:
                detail: Missing X-API-Key or $x$access-token header
        '403':
          description: >-
            API key authenticated but lacks the scope required for this
            endpoint, or the path's sport is not in the key's `sport_allowlist`.
            Use `GET /v1/whoami` to inspect the granted scope set.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: Human-readable error message.
                required:
                  - detail
              example:
                detail: >-
                  Required scope 'cs2:matches:detail' is not granted to this API
                  key. Contact your account manager to extend the key's scopes.
        '422':
          description: >-
            Validation error — a query/path parameter failed validation. The
            body lists the offending fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - type: enum
                    loc:
                      - query
                      - time_filter
                    msg: 'Input should be one of: 3m, 6m, 1y, all'
                    input: 2w
        '429':
          description: >-
            Tenant rate limit exceeded. Default is 600 req/min per tenant;
            configurable per contract. WebSocket connections are not
            rate-limited at the request layer.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: Human-readable error message.
                required:
                  - detail
              example:
                detail: Rate limit exceeded (600 req/min)
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
                example: 30
      security:
        - XAPIKeyHeader: []
        - XAccessTokenHeader: []
        - UOFAccessTokenHeader: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    XAPIKeyHeader:
      type: apiKey
      description: Tenant API key issued during onboarding
      in: header
      name: X-API-Key
    XAccessTokenHeader:
      type: apiKey
      description: UOF-standard alias for the tenant API key
      in: header
      name: x-access-token
    UOFAccessTokenHeader:
      type: apiKey
      description: Deprecated alias for x-access-token (backward compatibility)
      in: header
      name: $x$access-token

````