I have a question about querying `string[]` fields...
# community-help
e
I have a question about querying
string[]
fields I have a schema that looks something like this:
Copy code
{
  name: 'properties',
  enable_nested_fields: true,
  fields: [
    {
      name: 'name',
      type: 'string',
    },
    {
      name: 'locationTokens',
      type: 'string[]',
      facet: true,
    },
  ],
}
and a sample data entry might be…
Copy code
{
  name: 'My Cool Cafe',
  locationTokens: ['Williamsburg', 'Brooklyn', 'New York City', 'New York, USA', 'Gentrification Fallout Zone']
}
I can query 'Williamsburg' and it works great. But I'm also doing typeahead searches where I want these tokens to show up, e.g. if I type in "New York" I'd like to see
New York City
and
New  York, USA
returned. Right now I'm just getting all documents, and reducing all the
locationTokens
hits for unique values, very inefficient. Is there a better way to say (say in SQL parlance)
SELECT distinct(locationToken) from properties.locationTokens
? Or do I just need a second Typesense collection to track them?
j
You would have to create one record per location in a separate collection, for this use-case
e
Got it. Okay, I had a previous iteration of this system that basically did that, I was just hoping I could get around it more cleverly. Thank you.
👍 1