React InstantSearch - Edit Existing Search via API


Re: React InstantSearch. When a user makes a search request via instantsearch widgets, is it possible to access the current search state and modify via API?


We have multiple prices per product, which the standard price refinements do not work for. Our working solution is to use client-side logic to further filter hits before rendering. Issue is sometimes our rendered hits are out-of-sync with the server (i.e. # of results is different, facets may not be in sync, etc.).

Potential Solution

If client-logic hits > 0, make API call to filter out those objectIds.
Then current searchState updates and renders (rather than us modifying the render).


Here is a solution I came up with:

Added a filter to the Configure widget, which is tied to an “exclude” state. If client-side logic decides a hit should be excluded, it will update exclude state, which will then update search results (keeping client and server in sync).

<Configure hitsPerPage={16} filters={`${this.state.exclude}`} />

New question

Is it possible to access all hits at once? The above solution will update state for each page, rather than all hits at once.

Current solution:

  1. There are initially 53 results.
  2. Once the user navigates to page 3, the client calculates 1 hit should be excluded.
  3. The results update to show 52 results.

Desired solution:

  1. Show 52 results (i.e. access all 53 results on page 1, rather than only the first 16 results).