CipherStash
CipherStash Documentation

FieldDynamicMatch

FieldDynamicMatch is like DynamicMatch but allows match queries to be scoped to specific fields not known ahead of time.

Supported Types

  • string

Index Definition

FieldDynamicMatch works just like DynamicMatch in that all string fields in a document will be indexed. However, it also indexes the field names of the string fields and provides an enhanced match function at query time.

import { CollectionSchema, downcase, ngram } from "@cipherstash/stashjs"

CollectionSchema.define<Employee>("employees").indexedWith(mapping => ({
  allText: mapping.FieldDynamicMatch({
    tokenFilters: [downcase],
    tokenizer: ngram({ tokenLength: 3 })
  })
})

Supported Query Operations

  • match (performs full text search)

Imagine that we have an employees collection but that the only index we have defined is called allText of type FieldDynamicMatch. In this case, even though we have not defined an index specifically for the jobTitle field, we can still perform a full text search narrowed down to that specific field.

let queryResult1 = await employees.all(
  employee => employee.allText.match("jobTitle", "CEO")
)