#community-help

Issue with Categories Facet in Typesense InstantSearch Adapter

TLDR David encountered an issue with not being able to add fields categories to facets. Kishore Nallan assisted in troubleshooting. After some back and forth communication, David finally managed to resolve the issue.

Powered by Struct AI

1

8
11mo
Solved
Join the chat
Nov 15, 2022 (11 months ago)
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
08:36 AM
Hi! Why can't I do faced search for my fields? Look at this image. I have materials.lvl0 as a facet, that works just as expected. but i also have categories.lvl0, categories.lvl1, and categories.lvl2 added exactly the same way, marked with facet: true in my schema and those categories doesn't show up here as options. This is using the typesense-instantsearch-adapter and Instantsearch. I'm thinking it's something with max_facet_values or something, but i cannot get it to work
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:52 AM
Can you confirm by hitting the /collections end-point that the collection schema indeed has facet: true defined?
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
10:56 AM
sure, here's the schema from the /collections end-point response.
{
    "created_at": 1668508755,
    "default_sorting_field": "priority",
    "enable_nested_fields": false,
    "fields": [
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "sku",
        "nested": false,
        "optional": false,
        "sort": false,
        "type": "string"
      },
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "productName",
        "nested": false,
        "optional": false,
        "sort": true,
        "type": "string"
      },
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "variantName",
        "nested": false,
        "optional": false,
        "sort": true,
        "type": "string"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "colors",
        "nested": false,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "type",
        "nested": false,
        "optional": false,
        "sort": false,
        "type": "string"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "designer",
        "nested": false,
        "optional": true,
        "sort": false,
        "type": "string"
      },
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "tags",
        "nested": false,
        "optional": false,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "price",
        "nested": false,
        "optional": false,
        "sort": true,
        "type": "int32"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "inStock",
        "nested": false,
        "optional": false,
        "sort": true,
        "type": "bool"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "shipmentDate",
        "nested": false,
        "optional": true,
        "sort": true,
        "type": "int64"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "categories.lvl0",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "categories.lvl1",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "categories.lvl2",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "materials.lvl0",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "materials.lvl1",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": true,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "materials.lvl2",
        "nested": true,
        "nested_array": 2,
        "optional": true,
        "sort": false,
        "type": "string[]"
      },
      {
        "facet": false,
        "index": true,
        "infix": false,
        "locale": "",
        "name": "priority",
        "nested": false,
        "optional": false,
        "sort": true,
        "type": "int32"
      }
    ],
    "name": "Variants EU B2C 2022-11-15 10:39:14",
    "num_documents": 1055,
    "symbols_to_index": [],
    "token_separators": []
  }
11:00
David
11:00 AM
what's strange to me is that materials.lvl0 works as expected and get's added to the resultState for SSR, while categories.lvl0|1|2 does not even though they're the same in the schema. they're both added to the DOM when i do findResultsState from Instantsearch.

this one works
<RefinementList attribute="materials.lvl0" limit={100} />

while this one does not and is not included as a facet in the returned resultState :s
<RefinementList attribute="categories.lvl2" limit={100} />
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:04 AM
To identify if the issue is on the frontend or backend, can you try doing a direct request with a simple search + facet on those fields that are not working?
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
11:05 AM
here's a link to a PR preview with this issue. https://hemcomenus-featssrsearch.gtsb.io/furniture/chairs-and-stools

here's how to replicate it.

- filter "Materials" to something. reload the page. notice the amount of search hits and the active filters before the client side js kicks in.
- add a "Categories" filter and do the same thing. notice the categories filter is not active until the client side js kicks in (that reads the query params in the url and updates the search)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:12 AM
Looks like an instantsearch related issue to me. cc Jason
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
03:17 PM
Yup, totally was. Thanks for nudging me into the right direction. I got it working at the end. Have stared at this for so long, so it helped rubber ducking it out here. Ignore me!

1