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

Get complete list of facet values (even when not in the result set), with doc_count=0 #47

Closed tfrancart closed 3 years ago

tfrancart commented 4 years ago

Very useful library, I love it.

Is there an option in the configuration to always return the full set of values for an aggregation, even for values that do not correspond to any item in the result set, with doc_count set to 0 ?

Or is there a workaround for this ? (I can retrieve the complete list of values for an aggregation by triggering an empty search, but it would be much more convenient in my situation to consistently retrieve complete list of values to update the view with all values, and set colors/icons according to if the value is selected and if it has some results).

Cheers

cigolpl commented 4 years ago

@tfrancart thanks for a feedback!

Returning the complete list of values even if the doc_count is 0 might be a good feature as a new configuration option. Feel free to make a PR.

Right now workaround like triggering an empty search to get all filters seems best

tfrancart commented 4 years ago

Hi, thanks for the answer. Unfortunately I don't have the Javascript skills nor the bandwith to contribute directly to the code. Maybe you could point to the exact place in lib.js where the modification should take place ? I'd be also happy to test any improvement, and contribute to documentation on that new parameter.

cigolpl commented 4 years ago

This .buckets function is responsible for returning values in filters behavior: https://github.com/itemsapi/itemsjs/blob/f19850f4856e079577cc6dc0ae3adfddbf430b67/src/lib.js#L277

Please let's try conjunction: false in filters as in example (https://github.com/itemsapi/itemsjs/blob/master/docs/configuration.md). Probably that is what you are looking for.

tfrancart commented 4 years ago

Thanks for coming back to me on this

Please let's try conjunction: false in filters as in example (https://github.com/itemsapi/itemsjs/blob/master/docs/configuration.md). Probably that is what you are looking for.

This is not quite what I am looking for. With conjunction: false, I always get the same values in the aggregation, with the same doccount, independantly of the current result set. I think this really means : "this facet should be interpreted as an OR, so the user should be able to select multiple values from it, including values that are outside of the current result set, so let's always return the complete list of values, with total doccount". I need the same thing, but with the doc_count updated with respect to the current result set. I don't know if this could be an update of the existing conjunction: false flag, or if this requires a separate option.

cigolpl commented 3 years ago

Hey @tfrancart, this issue has been resolved in the new version 2.0.0. All filters are listed now even if positive number or 0. You can test it out here https://jsfiddle.net/cigol/0ef9qeos/181.

If that's still not working properly please reopen