#community-help

Dynamic Filtering in Search Query

TLDR Babin asks how to use dynamic filtering in their search query. Jason explains that overrides should be created separately after creating the collection.

Powered by Struct AI

1

3
7mo
Solved
Join the chat
Mar 10, 2023 (7 months ago)
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
11:43 PM
I am using below search query
{
    "q": "cheese",
    "query_by": "description,brand,categoryName,sku",
    "filter_by": "",
    "page": 1,
    "per_page": 30,
    "sort_by": "description:asc",
    "include_fields": "id,sku,description,categoryName,brand,packSizeDescription,images"
}

client.collections(collectionName).documents().search(searchParameters)

How do I use Dynamic Filtering ?
override = {
  "rule": {
    "query": "{brand} phone",
    "match": "contains"
  },
  "filter_by": "brand:={brand}",
  "remove_matched_tokens": true
}

// Creates/updates an override called `brand-filter` in the `companies` collection
client.collections('companies').overrides().upsert('brand-filter', override)

Do we have to add the overrides during collection setup?
Reference from: https://typesense.org/docs/0.23.1/api/curation.html#dynamic-filtering
Mar 11, 2023 (7 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:11 AM
Once you’ve created the collection, you would then create overrides after that separately
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
02:44 AM
Thanks Jason

1