#community-help

Resolving Issues with 'React-InstantSearch'

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

Powered by Struct AI

3

28
15mo
Solved
Join the chat
Aug 03, 2022 (15 months ago)
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
09:24 PM
Any thoughts on how to support multiple collection searches with react-instantsearch ? I have two collections that I would like to combine results for. They have different fields in each collection though. Do I need to do some kind of overriding of the react-instantsearch-hooks-web to support federated multisearch? Any ideas on where I would want to inject in this call?

I see support for this was built into the typesense react instant search adapter but I don't see any documentation on how to make a federated search possible. Is there documentation I can look at or could someone perhaps point me in the right direction?
09:33
robert
09:33 PM
I see this comment here but I can't seem to click into the instructions on how to delineate the specific query_by...

https://github.com/typesense/typesense-instantsearch-adapter/issues/38#issuecomment-823752445
09:39
robert
09:39 PM
Ok I think I'm figuring it out:

  // Search parameters that are common to all collections/indices go here:
  additionalSearchParameters: {
    query_by: "",
  },
  // Search parameters that need to be *overridden* on a per-collection-basis go here:
  collectionSpecificSearchParameters: {
    snippets: {
      query_by: "answer,name",
      query_by_weights: "2,1",
    },
    searchable: {
      query_by: "text,context",
      query_by_weights: "2,1",
    },
  },

Now I'm working out some of the kinks in having multiple Index within the InstantSearch
09:47
robert
09:47 PM
I'm getting undefined for highlight results weirdly...
09:48
robert
09:48 PM
When the matchLevel is full the value is undefined for all highlight fields in multi / federated search. When I do normal query by I don't have any issue with highlight results
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:21 PM
collectionSpecificSearchParameters is the way to go.

The undefined behavior sounds strange. Could you try using the latest version of the instantsearch adapter and at least Typesense 0.23.1 to see if you can replicate the issue?
10:21
Jason
10:21 PM
If you can still replicate it, this could be a bug in the adapter. Could you open a Github issue with a minimal example where I can replicate the issue locally? I can then debug it
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
10:59 PM
Perhaps its becaues my cluster is on v0.23.0 and i'm using latest libraries. Waiting to upgrade my cloud cluster. Gonan try testing on a local cluster
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:01 PM
I saw your upgrade request come through. Happy to queue it up now if you’d like. Let me know
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:01 PM
That'd be great 🙂

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:05 PM
You’re all set.
11:05
Jason
11:05 PM
I doubt this is an issue on the Typesense server side, since you were already running a pretty recent version, but let’s see!
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:15 PM
Thanks! Your hypothesis is right tho 🙂 Gonna put together a small sandbox to replicate issue. Is there a public cloud instance to test against in the sandbox? I can just leave creds empty for it
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:23 PM
Yeah you can leave the creds empty
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:32 PM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:39 PM
Would you be ok if we accessed the data in your cluster to debug this issue? (Need your explicit permission before we access user data)
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:41 PM
For sure

1

11:42
robert
11:42 PM
Just a testing cluster rn so no PII data

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:49 PM
Ah I see what’s going on. It looks like you’re using the <Highlight /> component. By default Typesense snippets results. So when you use <Highlight />, the field it’s looking for doesn’t exist in the Typesense response and it displays as undefined.

If you add a param called highlight_full_fields like below, you should then start seeing the highlights instead of undefined.

collectionSpecificSearchParameters: {
    snippets: {
      query_by: "answer,name",
      query_by_weights: "2,1",
      highlight_full_fields: "answer,name",
    },
    searchable: {
      query_by: "text,context",
      query_by_weights: "2,1",
      highlight_full_fields: "text,context",
    }
  }
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:50 PM
Jesus y'all might be faster than me at debugging and I don't say that lightly
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:51 PM
Hahaha! 😄
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:52 PM
So when I did just a single index it highlighted fine which was why I didn't even consider it was a configuration thing
11:52
robert
11:52 PM
I guess on the default query_by setup highlight full fields is set?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:52 PM
That is strange to hear though… I’m surprised it worked for a single index
11:52
Jason
11:52 PM
Oh hmm!
11:58
Jason
11:58 PM
https://typesense-community.slack.com/archives/C01P749MET0/p1659570739816799?thread_ts=1659561876.263559&cid=C01P749MET0

I just double-checked the adapter code. We don’t set a default for highlight full fields
robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
robert
11:59 PM
so weird. snippets work as expected as well (in federated search and query_by ). strange edge case
Aug 04, 2022 (15 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:00 AM
Yup, <Snippet /> will work by default, since Typesense snippets all query_by fields without additional configuration