Skip to main content
Perform a search query on an Orama database. Supports three search modes: full-text search, vector search, and hybrid search.

Signature

function search<T extends AnyOrama, ResultDocument = TypedDocument<T>>(
  orama: T,
  params: SearchParams<T, ResultDocument>,
  language?: string
): Results<ResultDocument> | Promise<Results<ResultDocument>>

Parameters

orama
AnyOrama
required
The Orama database instance to search.
params
SearchParams
required
Search parameters object. The structure depends on the search mode:
language
string
Language for tokenization and stemming (e.g., 'english', 'spanish').

Returns

count
number
Total number of matching documents.
hits
Result[]
Array of search results, each containing:
  • id: Document ID
  • score: Relevance score
  • document: The matched document
elapsed
object
Search execution time:
  • raw: Time in nanoseconds
  • formatted: Human-readable formatted time
facets
FacetResult
Facet aggregations (if requested).
groups
GroupResult[]
Grouped results (if requested).

Examples

import { create, insert, search } from '@orama/orama'

const db = await create({
  schema: {
    title: 'string',
    description: 'string',
    price: 'number'
  }
})

await insert(db, { title: 'Wireless Headphones', description: 'High quality', price: 99 })
await insert(db, { title: 'Bluetooth Speaker', description: 'Portable sound', price: 49 })

const results = await search(db, {
  term: 'headphones',
  properties: ['title', 'description'],
  limit: 10
})

console.log(results.hits) // [{ id: '...', score: 1.5, document: {...} }]
const db = await create({
  schema: {
    title: 'string',
    embedding: 'vector[384]'
  }
})

const results = await search(db, {
  mode: 'vector',
  vector: {
    value: [0.1, 0.2, 0.3, ...],
    property: 'embedding'
  },
  similarity: 0.8,
  limit: 5
})
const results = await search(db, {
  mode: 'hybrid',
  term: 'noise cancelling headphones',
  vector: {
    value: [0.1, 0.2, 0.3, ...],
    property: 'embedding'
  },
  hybridWeights: {
    text: 0.3,
    vector: 0.7
  },
  limit: 10
})

Search with Filters

const results = await search(db, {
  term: 'headphones',
  where: {
    price: {
      lt: 100,
      gte: 50
    }
  }
})

Search with Facets

const results = await search(db, {
  term: 'electronics',
  facets: {
    category: {
      limit: 10,
      sort: 'DESC'
    }
  }
})

console.log(results.facets)
// { category: { count: 50, values: { 'Audio': 20, 'Video': 30 } } }

Build docs developers (and LLMs) love