itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use
Apache License 2.0
346 stars 41 forks source link

Facet results for a given filter #8

Closed lbineau closed 6 years ago

lbineau commented 6 years ago

Hi @cigolpl, I'm not sure how facets usually work but I try to implement filters with count, something like this:

image

What is expected: When search returns results for a given filter value, the filter value should be part of the aggregation object.

What happens: When search returns results for a given filter value, the filter is not part of the aggregation object

I made a quick demo in the console (look at init console) https://codepen.io/lbineau/pen/RLxXKd?editors=0012

Is it a bug or a normal behavior?

cigolpl commented 6 years ago

Hey @lbineau, thanks for interesting case.

To be clear: You filter by job_field: ["7170452333"] and after searching facet results.data.aggregations.job_field.buckets returns you 10 elements and "7170452333" is not in the results

It's rather normal behavior because facet returns 10 results by default, sorted by count. You could see all result when you add size:

job_field: {
  conjunction: false,
  size: 100
}

Maybe it's also a good idea to add a new feature to facet like show_selected_in_top. I'll try to document all aggregations / facets options soon to make it more clear. Also I think we should change all aggregations into facets in the future because it can be misleading.

lbineau commented 6 years ago

It is what I need and solved my problem! Sounds good :)