#community-help

Troubleshooting Typesense Instantsearch Adapter's 'filters' Property

TLDR Carl was unable to use the filters property of Typesense Instantsearch adapter for network call. Jason suggested using a scoped API key to combine filters and also recommended experimenting with dynamic filtering rules for multiple product numbers. Carl is satisfied with these solutions.

Powered by Struct AI

2

1

1

Mar 25, 2022 (22 months ago)
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
10:06 AM
Hey, regarding the Typesense Instantsearch adapter. Should the filters property for <Configure> also work (docs) for Typesense? I have tried setting it but nothing seems to make it to the network call to Typesense.

I have used facetFilters previously which works great, though we can't set that and use a RefinementList at the same time. I was hoping using the filters property would somehow combine the values for us properly as described in this issue.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:26 AM
10:27
Jason
10:27 AM
Oh wait, you're talking about combining filters in the configure widget along with filters used in RefinementLists
10:27
Jason
10:27 AM
To do this in Typesense, I'd recommend embedding the filter in a scoped API key and using that API key with the adapter
10:28
Jason
10:28 AM
Then Typesense will combine the filter from the widget with the filter embedded in the API key on the server-side
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
10:34 AM
Hmm, that could work. Though we already do use a scoped API key as a way of controlling permissions on certain items, so not sure if it'll play nicely with that.

I can have a try though, it's the best I have right now 👍
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:35 AM
You can embed any number of fields in filter_by in scoped API keys, they'll all just be ANDed to the filter_by in the search query
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
10:37 AM
Can we extend a key though? We generate a scoped API key on login, and save that in the user's JWT.

This filtering would need to happen further along the process. I was about to try base64 decode the key and try modify the filter that way, to see if it worked
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:19 PM
> try base64 decode the key and try modify the filter that way
That wouldn't work unfortunately. It's meant to not be decodable for ACL purposes.

1

04:20
Jason
04:20 PM
Could you elaborate on your use case so I have context? May be there are other ways to do this

1

Mar 28, 2022 (21 months ago)
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
06:26 AM
Sure 🙂

What we have, is a search box, that when the user enters some text, we try to see if it contains numbers with length of 6. In this case, we assume the user wants to search on a bunch of product numbers, so we switch from doing a normal search query to just do a "*" and then filter on "product_number:<query_number>".

However, it could be that the user then wants to filter this result further, by using the refinements on the left. Which is where we hit the problem of the <Configure> not combining with the refinements.

Hope that makes sense
06:30
Carl
06:30 AM
Oh and, the search box is managed in a context, as we did not wish to depend on Instantsearch too much where possible.
Mar 31, 2022 (21 months ago)
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
05:47 AM
Jason Have any further thoughts on this? :thinking_face:
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:51 PM
> then filter on "product_number:<query_number>".
Does this not filter down to a single record? Sounds like there are multiple records with the same product number?
03:53
Jason
03:53 PM
If so, I think Dynamic Filtering might work for your use case: https://typesense.org/docs/0.22.2/api/curation.html#dynamic-filtering

Something like:

{
  "rule": {
    "query": "{product_number}",
    "match": "contains"
  },
  "filter_by": "product_number:={product_number}",
  "remove_matched_tokens": true
}

1

Apr 01, 2022 (21 months ago)
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
07:37 AM
Yeh, there are multiple records with the same identifier. Think of it as a single product, but with different colours, so each colour is an entry in itself. e.g. you sell a car, but that car has different variants. You sell the variants, but not the general shape/spec of the car 😄

I had come across the dynamic filtering rules, but didn't experiment with it. Would it work if there's 10 different product numbers? How about if there's a mix of different numbers? Such as:
"<product_number> <product_number> <ean> <product_number> <sub_product_number>"

If I were to make 3 rules, each targeting the different number types, they would all apply to a filter_by and be removed from the query? Assumiing remove_matched_tokens is true of course.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:11 PM
> Would it work if there's 10 different product numbers? How about if there's a mix of different numbers?
Yup, you also want to create different rules for each field, like you mentioned
Apr 04, 2022 (21 months ago)
Carl
Photo of md5-b4b5ae6f21ade3ef3d7824c4b63090c3
Carl
06:26 AM
Okay, sounds like that would do the job then. I'll give it a try! Thanks for the help ❤️

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Modifying Typesense's OR on filter_by & Multi-Query Workaround

Carl inquired about Typesense's OR on filter_by and multi-query workaround. Kishore Nallan gave an estimated timeline and a workaround for the OR query. Jason suggested custom widget creation for precise search queries and Dynamic Filtering rule set up.

3

11
22mo

Fixing Multiple Document Retrieval in Typesense

Phil needed an efficient way to retrieve multiple documents by id. Kishore Nallan proposed a solution available in a pre-release build. After some bug fixing regarding id matching by Jason and Kishore Nallan, Phil successfully tested the solution.

4

26
26mo

Troubleshooting Typesense Setup and Understanding Facets and Keywords

Demitri encountered errors when exploring Typesense for the first time. Jason guided them through troubleshooting and discussed facets, keyword settings, and widget configurations. Helin shared a Python demo app and its source code to help Demitri with their project.

1

56
21mo

Typesense Products Filtering Issue with Mixed AND+OR Filtering

Dmytro faced issues in implementing mixed AND+OR filtering for product filtering on Typesense using `'typesense-instantsearch-adapter'` despite using several approaches and facets. Jason suggested increasing the number of facets fetched and trying a different server version but the issue remains.

8
18mo

Typesense Ecommerce Storefront Showcase Discussion

Mica discussed enhancements and filters for an ecommerce storefront using Typesense. Jason offered resources on filters and handling facets count issues reported by Claudiu. Jason also implemented a solution to fix the problem.

7

13
31mo