> ## 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.

# Query Parser

> Accept raw user-provided query strings

The parse query accepts a [Tantivy query string](https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html).
The intended use case is for accepting raw query strings provided by the end user.

To use it, pass the table name or alias to the left-hand side of `@@@` and `pdb.parse('<query>')` to the right-hand side.
Passing an indexed column with `pdb.parse()` also remains supported.

```sql SQL theme={null}
SELECT description, rating, category FROM mock_items
WHERE mock_items @@@ pdb.parse('description:(sleek shoes) AND rating:>3');
```

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

await db
  .select({
    description: mockItems.description,
    rating: mockItems.rating,
    category: mockItems.category,
  })
  .from(mockItems)
  .where(search.parse(mockItems.id, "description:(sleek shoes) AND rating:>3"));
```

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

MockItem.objects.filter(
    id=ParadeDB(Parse('description:(sleek shoes) AND rating:>3'))
).values('description', 'rating', 'category')
```

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

stmt = (
    select(MockItem.description, MockItem.rating, MockItem.category)
    .where(search.parse(MockItem.id, "description:(sleek shoes) AND rating:>3"))
)

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

```ruby Rails theme={null}
MockItem.search(:id)
        .parse("description:(sleek shoes) AND rating:>3")
        .select(:description, :rating, :category)
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Parse(item.Id, "description:(sleek shoes) AND rating:>3")
    )
    .Select(item => new { item.Description, item.Rating, item.Category })
    .ToListAsync();
```

Please refer to the [Tantivy docs](https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html) for an overview of
the query string language.

## Lenient Parsing

By default, strict syntax parsing is used. If the query has invalid syntax or names an unknown field, it fails.
By setting `lenient` to `true`, the query is executed on a best-effort basis, ignoring invalid parts.
Terms without a field name search across indexed fields in both modes.

```sql SQL theme={null}
SELECT description, rating, category FROM mock_items
WHERE mock_items @@@ pdb.parse('description:(sleek shoes) AND rating:>3', lenient => true);
```

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

await db
  .select({
    description: mockItems.description,
    rating: mockItems.rating,
    category: mockItems.category,
  })
  .from(mockItems)
  .where(
    search.parse(mockItems.id, "description:(sleek shoes) AND rating:>3", {
      lenient: true,
    }),
  );
```

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

MockItem.objects.filter(
    id=ParadeDB(Parse('description:(sleek shoes) AND rating:>3', lenient=True))
).values('description', 'rating', 'category')
```

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

stmt = (
    select(MockItem.description, MockItem.rating, MockItem.category)
    .where(search.parse(MockItem.id, "description:(sleek shoes) AND rating:>3", lenient=True))
)

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

```ruby Rails theme={null}
MockItem.search(:id)
        .parse("description:(sleek shoes) AND rating:>3", lenient: true)
        .select(:description, :rating, :category)
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Parse(
            item.Id,
            "description:(sleek shoes) AND rating:>3",
            lenient: true
        )
    )
    .Select(item => new { item.Description, item.Rating, item.Category })
    .ToListAsync();
```

## Conjunction Mode

By default, terms in the query string are `OR`ed together. With `conjunction_mode` set to `true`, they are instead `AND`ed together.
For instance, the following query returns documents containing both `sleek` and `shoes`.

```sql SQL theme={null}
SELECT description, rating, category FROM mock_items
WHERE mock_items @@@ pdb.parse('description:(sleek shoes)', conjunction_mode => true);
```

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

await db
  .select({
    description: mockItems.description,
    rating: mockItems.rating,
    category: mockItems.category,
  })
  .from(mockItems)
  .where(
    search.parse(mockItems.id, "description:(sleek shoes)", {
      conjunctionMode: true,
    }),
  );
```

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

MockItem.objects.filter(
    id=ParadeDB(Parse('description:(sleek shoes)', conjunction_mode=True))
).values('description', 'rating', 'category')
```

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

stmt = (
    select(MockItem.description, MockItem.rating, MockItem.category)
    .where(search.parse(MockItem.id, "description:(sleek shoes)", conjunction_mode=True))
)

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

```ruby Rails theme={null}
MockItem.search(:id)
        .parse("description:(sleek shoes)", conjunction_mode: true)
        .select(:description, :rating, :category)
```

```cs EF Core theme={null}
await dbContext
    .MockItems.Where(item =>
        EF.Functions.Parse(
            item.Id,
            "description:(sleek shoes)",
            null,
            true
        )
    )
    .Select(item => new { item.Description, item.Rating, item.Category })
    .ToListAsync();
```


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