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

# Multiple Tokenizers Per Field

> Apply different token configurations to the same field

In many cases, a text field needs to be tokenized multiple ways. For instance, using the [unicode](https://www.paradedb.com/docs/reference/tokenizers/available-tokenizers/unicode.md)
tokenizer for search, and the [literal](https://www.paradedb.com/docs/reference/tokenizers/available-tokenizers/literal.md) tokenizer for [Top K ordering](https://www.paradedb.com/docs/reference/full-text/top-k.md).

To tokenize a field in more than one way, append an `alias=<alias_name>` argument to the additional tokenizer configurations.
The alias name can be any string you like. For instance, the following statement tokenizes `description` using both the simple and literal tokenizers.

```sql theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (
  id,
  (description::pdb.literal),
  (description::pdb.simple('alias=description_simple'))
);
```

Under the hood, two distinct fields are created in the index: a field called `description`, which uses the literal tokenizer,
and an aliased field called `description_simple`, which uses the simple tokenizer.

To query against the aliased field, cast it to `pdb.alias('alias_name')`:

```sql SQL theme={null}
-- Query against `description_simple`
SELECT description, rating, category
FROM mock_items
WHERE description::pdb.alias('description_simple') ||| 'Sleek running shoes';

-- Query against `description`
SELECT description, rating, category
FROM mock_items
WHERE description ||| 'Sleek running shoes';
```

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

// Query against `description_simple`
await db
  .select({
    description: mockItems.description,
    rating: mockItems.rating,
    category: mockItems.category,
  })
  .from(mockItems)
  .where(
    search.matchAny(
      search.alias(mockItems.description, "description_simple"),
      "Sleek running shoes",
    ),
  );

// Query against `description`
await db
  .select({
    description: mockItems.description,
    rating: mockItems.rating,
    category: mockItems.category,
  })
  .from(mockItems)
  .where(search.matchAny(mockItems.description, "Sleek running shoes"));
```

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

# Query against `description_simple`
MockItem.objects.extra(
    where=["(description::pdb.alias('description_simple')) ||| 'Sleek running shoes'"]
).values('description', 'rating', 'category')

# Query against `description`
MockItem.objects.filter(
    description=ParadeDB(MatchAny('Sleek running shoes'))
).values('description', 'rating', 'category')
```

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

# Query against `description_simple`
stmt_alias = (
    select(MockItem.description, MockItem.rating, MockItem.category)
    .where(search.match_any(pdb.alias(MockItem.description, "description_simple"), "Sleek running shoes"))
)

# Query against `description`
stmt = (
    select(MockItem.description, MockItem.rating, MockItem.category)
    .where(search.match_any(MockItem.description, "Sleek running shoes"))
)

with Session(engine) as session:
    {
        "rows_alias": session.execute(stmt_alias).all(),
        "rows": session.execute(stmt).all(),
    }
```

```ruby Rails theme={null}
# Query against `description_simple`
MockItem.search(:description_simple)
        .match_any("Sleek running shoes")
        .select(:description, :rating, :category)

# Query against `description`
MockItem.search(:description)
        .match_any("Sleek running shoes")
        .select(:description, :rating, :category)
```

```cs EF Core theme={null}
// Query against `description_simple`
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAny(
            EF.Functions.Alias(item.Description, "description_simple"),
            "Sleek running shoes"
        )
    )
    .Select(item => new { item.Description, item.Rating, item.Category })
    .ToListAsync();

// Query against `description`
await dbContext
    .MockItems.Where(item =>
        EF.Functions.MatchAny(item.Description, "Sleek running shoes")
    )
    .Select(item => new { item.Description, item.Rating, item.Category })
    .ToListAsync();
```

> [!NOTE]
>
> If a text field uses multiple tokenizers and one of them is [literal](https://www.paradedb.com/docs/reference/tokenizers/available-tokenizers/literal.md), we recommend aliasing
> the other tokenizers and leaving the literal tokenizer un-aliased. This is so queries that `GROUP BY`, `ORDER BY`, or aggregate the
> text field can reference the field directly:
>
> ```sql SQL theme={null}
> CREATE INDEX search_idx ON mock_items
> USING paradedb (
>   id,
>   (description::pdb.literal),
>   (description::pdb.simple('alias=description_simple'))
> );
>
> SELECT description, rating, category
> FROM mock_items
> WHERE description @@@ 'shoes'
> ORDER BY description
> LIMIT 5;
> ```


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