Skip to content

Filters

You can use the filters interface to filter the search results.

Filters are available for numeric, boolean, string, enum, and geopoint properties. Depending on the type of the property, you can use different operators.

String operators

On string properties it performs an exact matching on tokens so it is advised to disable stemming for the properties you want to use filters on (when using the default tokenizer you can provide the stemmerSkipProperties configuration property).

If we consider the following schema:

javascript
const db = await create({
  schema: {
    title: 'string',
    tag: 'string'
  },
  components: {
    tokenizer: {
      stemming: true,
      stemmerSkipProperties: ['tag']
    }
  }
})

const results = await search(db, {
  term: 'prestige',
  where: {
    'tag': 'new',
  },
})

The results will contain all documents that contain the word prestige in the title property and have tags property equal to new.

You can also specify a list of string, in this case it will return all documents that contain at least one of the values provided:

javascript
const results = await search(db, {
  term: 'prestige',
  where: {
    'tag': ['favorite', 'new'],
  },
})

Number operators

The number properties support the following operators:

OperatorDescriptionExample
gtGreater thanyear: { gt: 2000 }
gteGreater than or equal toyear: { gte: 2000 }
ltLess thanyear: { lt: 2000 }
lteLess than or equal toyear: { lte: 2000 }
eqEqual toyear: { eq: 2000 }
betweenBetween two values (inclusive)year: { between: [2000, 2008] }
javascript
const db = await create({
  schema: {
    id: 'string',
    title: 'string',
    year: 'number',
    meta: {
      rating: 'number',
      length: 'number',
      favorite: 'boolean',
      tags: 'string'
    },
  },
  components: {
    tokenizer: {
      stemming: true,
      stemmerSkipProperties: ['meta.tags']
    }
  }
})

const results = await search(db, {
  term: 'prestige',
  where: {
    year: {
      gte: 2000,
    },
    'meta.rating': {
      between: [5, 10],
    },
    'meta.length': {
      lte: 60,
    }
  },
})

Boolean operators

For boolean properties, you can simply set the property to true or false:

javascript
const results = await search(db, {
  term: 'prestige',
  where: {
    'meta.favorite': true,
  },
})

Enum operators

The enum properties support the following operators:

OperatorDescriptionExample
eqEqual togenre: { eq: 'drama' }
inContained in the given arraygenre: { in: ['drama', 'horror'] }
ninNot contained in the given arraygenre: { nin: ['commedy'] }

Enum[] operators

The enum properties support the following operators:

OperatorDescriptionExample
containsAllContains all the given valuesgenre: { containsAll: ['comedy', 'action'] }

Geosearch

Starting from Orama v2.0.0, you can perform geosearch queries.

Even though the APIs are very simple, we decided to dedicate a separate section for them. This lets us explain the concepts behind the geosearch and how it works with more details.

Read more about geosearch