Search Filter Count
Problem
We need to display filter counts on the search results page so users can see how many results match each filter option before applying it.
Case 1:
Use aggregation in the search query similar to booking.com: https://www.booking.com/city/id/jakarta.id.html This method can’t be applied to our current filter logic, which selects filters within a tag group (e.g. cuisine) using OR logic. OR logic prevents aggregation because filters combine disjunctively. This works great when all filters are using AND logic, similar to booking.com. Conclusion: Unless we change the filter logic to AND, it’s not applicable.
Branch:
-
https://github.com/hungryhub-team/hh-search/tree/feat/opensearch-filter-count-v1
-
https://github.com/hungryhub-team/hh-pegasus/tree/feat/filter-count-v1
Status: FAILED
Case 2:
Use a different query to aggregate the filter count based on search parameters (keyword, filter, etc.). This works but adds a little complexity to our codebase.
Commits:
-
https://github.com/hungryhub-team/hh-search/commit/9212d07d1a7b7ec4bf18b7317b9361f8c9a82719
-
https://github.com/hungryhub-team/hh-pegasus/commit/9b14e6fd990f8aa849083b3e86c45a8ab0fcad5c
Status: SUCCESS
I have searched the internet, but based on the research, this is the only viable approach I have found. Please let me know if you have a better solution for this.
Comparison
Case 1 is simpler but unusable; Case 2 is more complex but feasible.
Conclusion
Case 2 (the aggregation query approach) is the recommended path forward because it works with our existing OR-based filter logic.
Next Steps
Roll out in the next sprint after review and test coverage.