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

# Supported Query Types

> Use synonyms with match, phrase, fuzzy, and query parser queries

To add synonyms to a query, use `pdb.expand(<query>, <rule>)`, where

* `<query>` is the query string
* `<rule>` is the column containing the synonym rules.

For example, the following query replaces the query `leather couch` with its synonym set.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description &&& (SELECT pdb.expand('leather couch', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.matchAll(
      mockItems.description,
      search.expand("leather couch", shopSynonyms.rule),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, MatchAll, ParadeDB

results = MockItem.objects.filter(
    description=ParadeDB(MatchAll(Expand('leather couch', ShopSynonym, 'rule')))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.expand("leather couch", ShopSynonym.rule)

stmt = (
    select(MockItem.description)
    .where(search.match_all(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .match_all(ParadeDB.expand("leather couch", ShopSynonym, :rule))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAll(
            item.Description,
            Pdb.Expand("leather couch", dbContext.ShopSynonyms.Select(s => s.Rule))
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

Under the hood, the query string passed into `pdb.expand` is first split into tokens using the field's tokenizer (in this example, the tokenizer for `description`).
Each token is then looked up against the synonym index for `<rule>`, and expanded into a synonym set if a match is found.

The following queries support synonym expansion. If you require synonym support on additional query types, please [open a GitHub issue](https://github.com/paradedb/paradedb/issues).

## Match Conjunction

[`&&&`](https://www.paradedb.com/docs/reference/full-text/match#match-conjunction) requires **all** synonym groups to match.
Within each group, **any** alternative can match.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description &&& (SELECT pdb.expand('leather couch', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.matchAll(
      mockItems.description,
      search.expand("leather couch", shopSynonyms.rule),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, MatchAll, ParadeDB

results = MockItem.objects.filter(
    description=ParadeDB(MatchAll(Expand('leather couch', ShopSynonym, 'rule')))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.expand("leather couch", ShopSynonym.rule)

stmt = (
    select(MockItem.description)
    .where(search.match_all(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .match_all(ParadeDB.expand("leather couch", ShopSynonym, :rule))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAll(
            item.Description,
            Pdb.Expand("leather couch", dbContext.ShopSynonyms.Select(s => s.Rule))
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

## Match Disjunction

[`|||`](https://www.paradedb.com/docs/reference/full-text/match#match-disjunction) requires **any** synonym group to match.
A match for **any** alternative in any group is enough.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description ||| (SELECT pdb.expand('leather couch', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.matchAny(
      mockItems.description,
      search.expand("leather couch", shopSynonyms.rule),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, MatchAny, ParadeDB

results = MockItem.objects.filter(
    description=ParadeDB(MatchAny(Expand('leather couch', ShopSynonym, 'rule')))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.expand("leather couch", ShopSynonym.rule)

stmt = (
    select(MockItem.description)
    .where(search.match_any(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .match_any(ParadeDB.expand("leather couch", ShopSynonym, :rule))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAny(
            item.Description,
            Pdb.Expand("leather couch", dbContext.ShopSynonyms.Select(s => s.Rule))
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

## Phrase

[`###`](https://www.paradedb.com/docs/reference/full-text/phrase) requires **all** synonym groups to match together and in order.
Each group can match **any** of its alternatives, including alternatives containing multiple words.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description ### (SELECT pdb.expand('sleek sneakers', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.phrase(
      mockItems.description,
      search.expand("sleek sneakers", shopSynonyms.rule),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, ParadeDB, Phrase

results = MockItem.objects.filter(
    description=ParadeDB(Phrase(Expand('sleek sneakers', ShopSynonym, 'rule')))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.expand("sleek sneakers", ShopSynonym.rule)

stmt = (
    select(MockItem.description)
    .where(search.phrase(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .phrase(ParadeDB.expand("sleek sneakers", ShopSynonym, :rule))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Phrase(
            item.Description,
            Pdb.Expand("sleek sneakers", dbContext.ShopSynonyms.Select(s => s.Rule))
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

Like normal phrase queries, the subquery can be cast to [`::pdb.slop(...)`](https://www.paradedb.com/docs/reference/full-text/phrase#adding-slop).

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description ### (SELECT pdb.expand('sleek sneakers', rule) FROM shop_synonyms)::pdb.slop(1);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.phrase(
      mockItems.description,
      search.slop(search.expand("sleek sneakers", shopSynonyms.rule), 1),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, ParadeDB, Phrase, Slop

results = MockItem.objects.filter(
    description=ParadeDB(Phrase(Slop(Expand('sleek sneakers', ShopSynonym, 'rule'), 1)))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.slop(search.expand("sleek sneakers", ShopSynonym.rule), 1)

stmt = (
    select(MockItem.description)
    .where(search.phrase(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .phrase(ParadeDB.slop(ParadeDB.expand("sleek sneakers", ShopSynonym, :rule), 1))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Phrase(
            item.Description,
            Pdb.Slop(Pdb.Expand("sleek sneakers", dbContext.ShopSynonyms.Select(s => s.Rule)), 1)
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

## Fuzzy Matching

[Fuzzy matching](https://www.paradedb.com/docs/reference/full-text/fuzzy.md) applies to the search text, while synonyms remain exact matches.
Synonym rules are looked up using the query tokens without fuzzy matching, so misspelled tokens do not match rule keys.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description ||| (SELECT pdb.expand('sofa', rule) FROM shop_synonyms)::pdb.fuzzy(1);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.matchAny(
      mockItems.description,
      search.fuzzy(search.expand("sofa", shopSynonyms.rule), 1),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, Fuzzy, MatchAny, ParadeDB

results = MockItem.objects.filter(
    description=ParadeDB(MatchAny(Fuzzy(Expand('sofa', ShopSynonym, 'rule'), 1)))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.fuzzy(search.expand("sofa", ShopSynonym.rule), 1)

stmt = (
    select(MockItem.description)
    .where(search.match_any(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .match_any(ParadeDB.fuzzy(ParadeDB.expand("sofa", ShopSynonym, :rule), 1))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAny(
            item.Description,
            Pdb.Fuzzy(Pdb.Expand("sofa", dbContext.ShopSynonyms.Select(s => s.Rule)), 1)
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```

## Query Parser

[`@@@`](https://www.paradedb.com/docs/reference/full-text/query-parser) parses the query string before expanding its terms and quoted phrases.
Boolean operators, grouping, and phrase constraints still apply to the expanded synonym groups.
Use quotes around multi-word synonym keys so the parser treats them as a phrase.

```sql SQL theme={null}
SELECT description FROM mock_items
WHERE description @@@ (SELECT pdb.expand('sofa OR couch', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({ description: mockItems.description })
  .from(mockItems)
  .where(
    search.parse(
      mockItems.description,
      search.expand("sofa OR couch", shopSynonyms.rule),
    ),
  );
```

```python Django theme={null}
from paradedb import Expand, ParadeDB, Parse

results = MockItem.objects.filter(
    description=ParadeDB(Parse(Expand('sofa OR couch', ShopSynonym, 'rule')))
).values('description')
list(results)
```

```python SQLAlchemy theme={null}
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

rules = search.expand("sofa OR couch", ShopSynonym.rule)

stmt = (
    select(MockItem.description)
    .where(search.parse(MockItem.description, rules))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails theme={null}
MockItem.search(:description)
        .parse(ParadeDB.expand("sofa OR couch", ShopSynonym, :rule))
        .select(:description)
        .to_a
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Parse(
            item.Description,
            Pdb.Expand("sofa OR couch", dbContext.ShopSynonyms.Select(s => s.Rule))
        )
    )
    .Select(item => new { item.Description })
    .ToListAsync();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.