Search Configuration
Three parameters control global search behavior:
| Parameter | Type | Default |
|---|---|---|
enable_search |
bool |
True |
search_field |
str |
"q" |
search_columns |
list[str] |
[] |
enable_search
Toggles global search on or off entirely for a schema.
When False, the search_field parameter won't appear in the generated filter model and any value sent for it will be ignored (or rejected in strict mode).
search_field
The name of the query parameter used to trigger global search.
| Default | Custom |
|---|---|
GET /posts?q=hello |
GET /posts?query=hello |
Info
The search_field parameter is always excluded from strict mode validation — it's always considered a valid parameter when enable_search = True.
search_columns
A list of column names to search across. The library applies an OR clause with ILIKE '%value%' for each column.
class PostOut(BaseModel):
title: str = Field(json_schema_extra={"filters": ["eq"]})
description: str | None = Field(None)
class FilterConfig:
search_columns = ["title", "description"]
Request: GET /posts?q=stargate
Generated SQL:
Empty list = no search
If search_columns = [] (the default), global search is effectively disabled even if enable_search = True. You must explicitly declare the columns.
Searching Non-String Columns
If a column in search_columns is not a string type (e.g., Integer, Float, UUID), the adapter automatically casts it to String before applying ILIKE:
Generated SQL:
Searching Nested Fields
You can search across fields in related models by using the double-underscore notation:
The adapter will automatically perform the necessary JOIN and apply the search condition on the related table.
Request: GET /posts?q=john
Generated SQL:
JOIN users ON posts.user_id = users.id
WHERE posts.title ILIKE '%john%'
OR users.name ILIKE '%john%'
OR users.email ILIKE '%john%'