#community-help

Restricting HierarchicalMenu Search to a Specific Collection

TLDR gab needed to restrict the HierarchicalMenu component to search within a specific collection. Jason solved the issue by recommending they nest the HierarchicalMenu within an Index element.

Powered by Struct AI

1

Feb 11, 2022 (23 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
05:51 PM
Hi,
when using the HierarchicalMenu from 'react-instantsearch-dom' can we restrict the component so that search will be on a specific collection ?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:01 PM
gab IIRC by default it only works on a single collection...
07:02
Jason
07:02 PM
May be I don't understand the question fully
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
07:03 PM
In fact I have 2 collections (2 indexes) used in the <InstantSearch/> context. So when I try to use inside the HierarchicalMenu it tries to query the categories fields in both collection.
But in my case I only have those categories on one collection.
07:05
gab
07:05 PM
<InstantSearch>
  <Index indexName="col1" />
  <Index indexName="col2" />

  <HierarchicalMenu attributes={['categories.lvl0']}/>
</InstantSearch>
07:05
gab
07:05 PM
I saw I could have multiple InstantSearch context but I would like to avoid
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:01 PM
I haven't tried this myself... May be try nesting HierarchicalMenu within an Index element?
08:02
Jason
08:02 PM
Something like this:

<Index indexName="col2">
   <HierarchicalMenu attributes={['categories.lvl0']}/
</Index>
Feb 14, 2022 (23 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
11:36 AM
Ah you're right, that's working well, thanks !

1