#community-help

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

TLDR 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.

Powered by Struct AI

1

10
28mo
Solved
Join the chat
Aug 23, 2021 (29 months ago)
Kyle
Photo of md5-634dde0508c7b907c4bc5a5c9b5fe23a
Kyle
08:13 PM
Has anyone worked with passing the state of search to the backend for a search? I'm implementing an "Export" feature where I need to have all pages of results. I'm using the InstantSearch.js client on the frontend. My plan is to grab the additionalSearchParameters from TypesenseInstantsearchAdapter.configureation and the search state from search.helper.state.

Checking if there's a canonical / easier way 🙂 the backend is in Node fwiw
08:17
Kyle
08:17 PM
I have seen the API export but it doesn't look like it (yet) supports replicating a full query: https://typesense.org/docs/0.21.0/api/documents.html#export-documents
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:53 PM
Kyle The export endpoint only supports filter_by, include_fields and exclude fields.

So if you're not using text-based queries and only filters, then that would work. Otherwise, you would have to use search endpoint on the backend as well.
10:54
Jason
10:54 PM
re: grabbing search state to send to the backend, InstantSearch.js has this suggested mechanism: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/#searching-for-results

In fact, this is what the Typesense-Instantsearch adapter itself uses to send the search state to a Typesense backend
10:54
Jason
10:54 PM
So you could use that mechanism, post the whole search state to your backend, then use the Typesense Instantsearch adapter in your backend, to send the params posted from the frontend to Typesense.

I think this should work... but let me know if you run into any issues with getting the adapter to work in a node environment.
Kyle
Photo of md5-634dde0508c7b907c4bc5a5c9b5fe23a
Kyle
10:56 PM
Jason yep totally! Thank you for pointing me in the right direction. I'll dig into this

1

Sep 13, 2021 (28 months ago)
Kyle
Photo of md5-634dde0508c7b907c4bc5a5c9b5fe23a
Kyle
09:30 PM
Jason quick update here, I ran into issues using the Typesense InstantSearch Adapter on the backend. I did get it to successfully work using search.getUiState on the client and search.setUiState on the server. But I couldn't figure out how to respond to a search request without setting an arbitrary timeout to wait for results (it's "instant" after all 🙂 )

The Algolia docs were helpful but use their API client on the server vs. the InstantSearch lib. It seems the TS client and Algolia client are not compatible.

For my use case I need to run and process the results on the server vs. passing back to the client (similar to export with full query).

For now, my searches are fairly straightforward so I'm just going to translate the instant search format to something the TS client can use on the server
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:06 PM
Kyle

> so I'm just going to translate the instant search format to something the TS client can use on the server
This is what the InstantSearch adapter does, specifically this class: https://github.com/typesense/typesense-instantsearch-adapter/blob/0c9af2a2e0cec64b31bd5c3717f7289b5bbbe737/src/SearchRequestAdapter.js#L218

You might be able to use just that class, instead of the full adapter...
Sep 22, 2021 (28 months ago)
Kyle
Photo of md5-634dde0508c7b907c4bc5a5c9b5fe23a
Kyle
07:38 PM
Jason got back around to this - this worked! I had to also pull in the additionalSearchParameters and collectionSpecificSearchParameters in addition to the instantSearchRequest but was able to get the format the TS server needs. Thank you! 🙏
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:59 PM
That's great to hear! 🙌

Typesense

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

Indexed 3005 threads (79% resolved)

Join Our Community

Similar Threads

Typesense Sorting Query and Bug Report

michtio is new to Typesense and is querying sorting implementation. Jason shares resources and suggests use of specific adapters. However, michtio shares a bug found when applying a filter on Typesense. Jason asks for a GitHub issue to be opened for the bug.

14
18mo

Discussion on the Use of `TypesenseInstantSearchAdapter`

DavidLo sought advice to retrieve search results using `TypesenseInstantSearchAdapter`. Carl and Jason advised using `typesense-js` and features like `documents/export`, `documents/search`, `multisearch`, and pagination. The potential server-side solution and bundle size issues concerning the exposure of the search client were also discussed.

2

17
26mo
Solved

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
Solved

Implementing Search Suggestion/Autocomplete Functionality in Typesense

Denis needed advice on implementing search suggestions in Typesense. Jason provided a solution for fetching after 3+ letters. However, questions on design pattern and passing hooks remain unanswered.

1

4
21mo

Resolving Issues with 'React-InstantSearch'

robert was having trouble merging results from different collections using `react-instantsearch` and was facing issues with undefined highlight results. After much discussion, Jason provided a solution using `collectionSpecificSearchParameters` and `highlight_full_fields` to solve the problem.

3

28
17mo
Solved