#community-help

Resolving Issue with Instantsearch Sort_by in React

TLDR Edward had a problem with sorting functionality in a React component using Algolia's InstantSearch. Jason recommended a potential solution for specifying index names which resolved the issue.

Powered by Struct AI

1

1

Jun 17, 2022 (19 months ago)
Edward
Photo of md5-abd5ee17039f6a27ff7f2bc0e3ef7131
Edward
02:43 PM
We are using instantsearch in react, along with infinite hits. This is an old class based component that we are migrating from Algolia.
We have everything working accept the sort_by feature.
We’re using a normal (non Algolia) dropdown which dynamically changes the ‘sort_by’ parameter and causes a query to fire off. This works and results are returned, but the ‘hits’ remain the same as they were.
If we select a facet dropdown (which is an instantsearch widget), new results are pulled through with the sort too. Otherwise, the hits remain as they were.
We can see the network request so we know the hits we expect to come through are there, and the component is rendered, but the hits don’t change
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:14 PM
Edward When you say "normal (non Algolia) dropdown", you're still using the instantsearch connectors to build this custom widget right? That's the only way (AFAIK) to get instantsearch to integrate with other custom UI elements...
Edward
Photo of md5-abd5ee17039f6a27ff7f2bc0e3ef7131
Edward
03:25 PM
We stopped using the dropdown when we implemented typesearch as for some reason we never got results back and saw errors everytime we tried to use the 'connectSortBy'
03:25
Edward
03:25 PM
03:28
Edward
03:28 PM
Once removed, we started getting hits returned. But then the sort_by functionality has not worked as expected.
If we use 'Hits' instead of 'infiniteHits' our non-Algolia connected dropdown works flawlessly, but our component is based on infinite scrolling
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:40 PM
That 404 error might be fixable. I haven't used connectSortBy but I suspect the 404 might be because with the Typesense adapter you need to specify the index name in a specific way for sort by to work. For eg, here's the format for the default sortBy widget: https://github.com/typesense/typesense-instantsearch-adapter#sortby

Could you try setting the index name similarly in your custom widget?
Edward
Photo of md5-abd5ee17039f6a27ff7f2bc0e3ef7131
Edward
04:10 PM
🙏
04:11
Edward
04:11 PM
that solved it. thank you so much.

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:11 PM
Awesome! 🙌

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

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

Resolve Facets and Sorting Issues with Typesense

Ethan needed assistance with getting all facet values and sorting results by date using Typesense. Jason provided guidance on how to use Typesense properties to accomplish these tasks, and resolved issues related to specific use-cases provided by Ethan and Rushil.

11

70
4mo

Resolving 'stores_count' field sorting issue in Schema

em1nos encountered an issue sorting the 'stores_count' field, which was due to a field disparity in multiple collections. Upon resolving that, a subsequent issue with instant search internally managing sorting came up, which Jason addressed by releasing an updated version of the adapter.

5

41
31mo

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

Connecting React Instant Search with Typesense Adapter

KARTHICK sought help with an error when using Typesense Adapter for React Instant Search. Jason advised substituting import statements. After uninstalling the react-instantsearch-dom package, KARTHICK resolved the issue.

1

10
6mo