Filters
Filters allow you to narrow down search results based on specific property values. You can filter by numbers, strings, booleans, enums, and even perform geospatial filtering.
Basic Filtering
Use the where clause to filter search results:
import { create , insert , search } from '@orama/orama'
const db = create ({
schema: {
title: 'string' ,
description: 'string' ,
price: 'number' ,
category: 'string'
}
})
insert ( db , {
title: 'Noise cancelling headphones' ,
description: 'Best noise cancelling headphones on the market' ,
price: 99.99 ,
category: 'electronics'
})
const results = search ( db , {
term: 'Headphones' ,
where: {
price: {
lt: 100
}
}
})
Filter Operators
Number Filters
Filter numeric properties using comparison operators:
Less Than
Greater Than or Equal
Between Range
Equal To
const results = search ( db , {
term: 'headphones' ,
where: {
price: {
lt: 100
}
}
})
Between two values (inclusive)
String Filters
Filter string properties by exact match or array of values:
Exact Match
Multiple Values
const results = search ( db , {
term: 'product' ,
where: {
category: 'electronics'
}
})
Boolean Filters
Filter by boolean values:
const db = create ({
schema: {
title: 'string' ,
inStock: 'boolean'
}
})
const results = search ( db , {
term: 'headphones' ,
where: {
inStock: true
}
})
Enum Filters
Filter enum properties with comparison operators:
Equal To
In Array
Not In Array
const results = search ( db , {
term: 'movie' ,
where: {
genre: {
eq: 'drama'
}
}
})
eq
string | number | boolean
Equal to the specified value
Match any value in the array
Do not match any value in the array
Array Enum Filters
Filter on enum arrays with contains operators:
const db = create ({
schema: {
title: 'string' ,
tags: 'enum[]'
}
})
insert ( db , {
title: 'Premium Headphones' ,
tags: [ 'audio' , 'wireless' , 'noise-cancelling' ]
})
const results = search ( db , {
term: 'headphones' ,
where: {
tags: {
containsAll: [ 'audio' , 'wireless' ]
}
}
})
Document must contain all specified values
Document must contain at least one specified value
Logical Operators
AND Conditions
Combine multiple filter conditions (all must match):
const results = search ( db , {
term: 'headphones' ,
where: {
and: [
{
price: {
gte: 50
}
},
{
price: {
lt: 100
}
},
{
category: 'electronics'
}
]
}
})
Multiple properties in the same where object are implicitly combined with AND.
OR Conditions
Match any of the specified conditions:
const results = search ( db , {
term: 'headphones' ,
where: {
or: [
{
category: 'electronics'
},
{
category: 'audio'
},
{
price: {
lt: 50
}
}
]
}
})
NOT Conditions
Exclude documents matching the condition:
const results = search ( db , {
term: 'headphones' ,
where: {
not: {
category: 'refurbished'
}
}
})
Complex Nested Conditions
Combine multiple logical operators:
const results = search ( db , {
term: 'headphones' ,
where: {
and: [
{
or: [
{ category: 'electronics' },
{ category: 'audio' }
]
},
{
price: {
lt: 100
}
},
{
not: {
brand: 'generic'
}
}
]
}
})
Filter-Only Searches
You can perform filter-only searches without a search term:
// Returns all documents with price less than 100
const results = search ( db , {
where: {
price: {
lt: 100
}
}
})
When no term is provided, Orama returns all documents matching the filter with a score of 0.
Nested Property Filters
Filter on nested object properties:
const db = create ({
schema: {
title: 'string' ,
meta: {
rating: 'number' ,
reviews: 'number'
}
}
})
const results = search ( db , {
term: 'headphones' ,
where: {
'meta.rating' : {
gte: 4.5
}
}
})
Combining Filters with Search Modes
With Full-Text Search
const results = search ( db , {
term: 'headphones' ,
mode: 'fulltext' ,
where: {
price: {
lt: 100
},
inStock: true
}
})
With Vector Search
const results = search ( db , {
mode: 'vector' ,
vector: {
value: embeddings ,
property: 'embedding'
},
where: {
price: {
lt: 100
}
}
})
With Hybrid Search
const results = search ( db , {
mode: 'hybrid' ,
term: 'headphones' ,
vector: {
value: embeddings ,
property: 'embedding'
},
where: {
category: 'electronics' ,
price: {
between: [ 50 , 150 ]
}
}
})
Index Frequently Filtered Properties
Properties used in filters should be indexed for best performance: create ({
schema: {
price: 'number' , // Automatically indexed
category: 'string' // Automatically indexed
}
})
Use Specific Operators
Use eq for exact matches when possible, as it’s faster than range queries
Minimize Complex Nesting
Deep nesting of logical operators can impact performance. Keep filters as simple as possible.
Filter Before Search
Filters are applied during search, reducing the result set efficiently
Common Use Cases
E-commerce Filter products by price range, category, and availability
Content Filtering Filter articles by date, author, or category
User Search Find users by role, status, or registration date
Inventory Filter items by stock status, location, or quantity
Geosearch Filter by geographic location and radius
Facets Generate filter options from search results
Sorting Sort filtered results by properties
Full-Text Search Combine filters with text search