Skip to content

Hide irrelevant filters when they barely return products - #1355

Open
indykoning wants to merge 2 commits into
masterfrom
feature/hide-irrelevant-filters
Open

Hide irrelevant filters when they barely return products#1355
indykoning wants to merge 2 commits into
masterfrom
feature/hide-irrelevant-filters

Conversation

@indykoning

Copy link
Copy Markdown
Member

This PR attempts to hide irrelevant filters from listings.
As some examples:
A Category page with many different types of products could have a filter dedicated to a small subset of those products:
a filter with 4 options, one returning 19 products, one 13, one 2 and one 1.
We're on a category page with 622 products. This means on a page where we have 622 products we show a filter that would only ever be able to display a maximum of 35 products.

That's not a very relevant filter, however when we start filtering. Getting to 100 products that filter is relevant again. Calculating it to a percentage would be:
((19 + 13 + 2 + 1) / 622 * 100) = 5.6%
Filtering it a little to 176 products:
((19 + 13 + 2 + 1) / 176 * 100) = 19.8%

By calculating a percentage between total possible products in filter, and all current products we ensure only relevant filters that filter enough products are shown. But pages with only few products don't get impacted.

@indykoning
indykoning requested a review from royduin as a code owner August 13, 2026 15:09
Comment on lines +134 to +141
({ instantSearchInstance }) => {
this.instantSearchInstance = instantSearchInstance
return {
onStateChange: () => {},
subscribe: () => {},
unsubscribe: () => {},
}
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a middleware to the instantsearch initialization gives us easy access to the instantsearchInstance.

Hacks we've used in the past were

export default {
    inject: {
        instantSearchInstance: {
            from: '$_ais_instantSearchInstance',
        },
    },
   ...

Alternatively custom widgets could be used: https://www.algolia.com/doc/guides/building-search-ui/widgets/create-your-own-widgets/vue
That would mean every filter would need another Vue component wrapping it.

This current method gives us access to the instantSearchInstance within any Listing component.

@royduin

royduin commented Aug 19, 2026

Copy link
Copy Markdown
Member

Looking good to me, let's wait for a review from @Jade-GG + successful Playwright tests

@royduin
royduin requested a review from Jade-GG August 19, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants