Prefix query search in FQL v10

I have the following data:

{
 .... 
 name: 'John Doe',
 ...
}

In FQL v10, how can we search collections by prefix substring? For instance, if I input the string 'john', it should return all mentioned data with that prefix. What should the index creation and query process look like? I’ve only found discussions and examples using v4.

Hello @miro and welcome!

With Computed Fields you can calculate values that can be indexed on, other than the fields persisted in the documents.

For example

collection Customer {
  // create an array of whole words to match
  compute nameSearch: Array<String> = (
    doc => doc.name.casefold().split(" ")
  )

  // an index that can match any items in the calculated `nameSearch` field
  index nameSearch {
    terms [mva(.nameSearch)]
  }
}

Which would allow a query like this

Customer.nameSearch("john")
1 Like

What is the best way to search on an index like this with multiple terms? Let’s say I wanted to get only John Does and not John Smith or Jane Doe.

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