Does FQL v10 support wildcard searches?

Does FQL version 10 support wildcard searches?

==> FQL X for SQL users - Fauna Documentation

for example, where customer.name like ‘%smith%’?

(the old FQL does not support any wildcard searches)

Strings in v10 have the .includes method.

For example,

let search = "Smith"

Customer.all().where(c => {
  let normalized = c.name.casefold()
  normalized.includes(search.casefold())
})

Please note that using where on a Collection doesn’t use any indexes, it runs a full Collection scan for results.

This is similar to the ContainsStr function in version 4,

how do you do wildcard searches using an index?
=> i want to avoid full table scan when doing wildcard/contains searches

You can only search an index for terms that are covered by the index. If you want a more wild-card-like search, then you will need to compute the fields necessary to index them. This is similar to FQL v4.

This is often done with index bindings in FQL v4. FQL v10 will not have index bindings, though we are working on providing similar functionality through computed fields, which will be defined on the collection rather than specific indexes.

In the meantime, you can write the fields to your documents directly.

Customer.create({
  name: "Agent Smith",
  nameSearch: generateNameSearch("Agent Smith")
})

Where generateNameSearch is some UDF that returns an array of useful terms, e.g.

["age", "gen", "ent", "smi", "mit", "ith"]

Integrating with third-party search tools

This approach is reasonably performant for small strings, such as names, but if you want to do sophisticated searches with larger text fields, then we recommend syncing your Fauna data with a data warehouse or search engine, for example Algolia, ElasticSearch, Typesense, etc.

One way you can do that is through Airbyte. We have partnered with Airbyte to provide a source connector to export and sync your data to other providers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.