#community-help

Typesense Search/Filter/Query Context with InstantSearch Adapter

TLDR Jainil wanted to access typesense parameters for bulk operations. Jason suggested accessing the 'uiState' of the widgets and proposed making _buildSearchParameters a public method. They also discussed the differences between uiState and instantsearchRequest.params in context of typesense parameters.

Powered by Struct AI
Aug 18, 2023 (3 months ago)
Jainil
Photo of md5-bea1e4531665b4608c47d00462429d3a
Jainil
03:22 PM
Is it possible to get the context of the typesense search/filter/query params using the instantsearch adapter? I.e we have the ability to filter on some refinement properties and we also set some custom filters using Configure. We want our user to be able to perform bulk actions on the selection they have filtered down on, so want to pass the typesense params to our backend server so it can perform the operation
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:49 PM
Interesting use-case!
04:49
Jason
04:49 PM
May be something like this could help to access the state of the widgets: https://www.algolia.com/doc/guides/building-search-ui/going-further/access-state-outside-lifecycle/js/

And send that state to the backend?
Aug 23, 2023 (3 months ago)
Jainil
Photo of md5-bea1e4531665b4608c47d00462429d3a
Jainil
08:05 PM
That's awesome. So accessing uiState will definitely give me both the state of things in <Configure/> and <RefinementsLists/>.

Is there any way that some of the helper functions in https://github.com/typesense/typesense-instantsearch-adapter/blob/master/src/SearchRequestAdapter.js#L361 can be exposed as part of the searchadapter API? Would love to not have to rewrite these for the filters, and be more robust to potential changes
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:56 PM
Sure, happy to convert the _buildSearchParameters to a public method, so you can use it by instantiating SearchRequestAdapter. Do you want to do a PR that renames that method to transformSearchParameters?
Jainil
Photo of md5-bea1e4531665b4608c47d00462429d3a
Jainil
08:56 PM
Sure 🙂
11:11
Jainil
11:11 PM
Wanted to get your take on the approach here - and I haven't fully dug around instantsearch to figure this out yet.

The uiState provides the following data -> the index keying a dict with the different refinementLists/menus/configure "filter"/ranges.
{"profiles":{"range":{"mixed_profile.years_of_experience":"3:4"},"refinementList":{"mixed_profile.skills":["C++"]},"menu":{"segments.id":"kpu9rfNB"},"configure":{"filters":"(mixed_profile.location: NY)"}}}

It seems as though _buildSearchParameters (or transformSearchParameters ) uses the instantsearchRequest.params to transform "algolia params" into "typesense params", so basically the parsing of the uiState into these params is already built into instantsearch.

Wouldn't it be better for the instantsearchadapter to use the uiState directly instead of using algolias params to convert into the typesense params? Detaching from the double-conversion could allow for the implementation of features like multiple geo filters (which algolia only limits to one field).

For my use case, exposing of the transformSearchParameters into a public method would be very useful, but I'd still have to dig around instantsearch to find where uiState is converted into the algolia params (or also possibly build that myself, which isnt a huge deal considering low # of filter types)
11:12
Jainil
11:12 PM
Either way, thanks for the help! Happy to help contribute to the repo/bettering the tool.
Aug 24, 2023 (3 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:13 AM
Ah hmm, I didn’t realize the uiState data structure was not the same as the instantsearchRequest.params

> Wouldn’t it be better for the instantsearchadapter to use the uiState directly instead of using algolias params to convert into the typesense params?
If it’s available sure, but I don’t think the uiState data structure is available within the searchClient context… Instead Algolia only sends the resolved search params.

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

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

Refine Method Issue in Typesense Instant-Search Adapter

Ankit has trouble using the refine method for geopoint fields in the typesense instant-search adapter. Jason identified the issue in the CURL request and proposed alternatives while prepping to address the issue in the adapter.

2

18
1mo

Implementing State Export Feature Using Typesense InstantSearch.js on Node.js Backend

Kyle needed help passing search state to backend for implementing an "Export" feature, while using Typesense InstantSearch. Jason provided multiple solutions including advice on using Typesense InstantSearch adapter. The issue was resolved after some iteration.

1

10
28mo

Typesense Capabilities and Troubleshooting Queries

A had issues with refinement lists and analytics in Typesense. Jason provided a possible solution and recommended the analytics widget. They clarified import size limits and helped identify a filter issue in A's query. Upgrade options are in Typesense's roadmap.

4

32
35mo

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