itemsapi / itemsjs

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

Feature request - min and max values #95

Closed Ruitjes closed 2 years ago

Ruitjes commented 2 years ago

Hello Cigolpl,

Thanks for the library.

I would like to use the min and max values from numeric fields, e.g. price. These are the min and max values, after searching/filtering the data set. It is handy for dynamically updating the min and max value in a range input.

Is there a way to do this or is this something you are working on?

cigolpl commented 2 years ago

@Ruitjes, you can filter by using filter option. Please look at https://github.com/itemsapi/itemsjs/blob/master/docs/configuration.md or https://github.com/itemsapi/itemsjs/issues/30

Ruitjes commented 2 years ago

@cigolpl Thanks for your response

That isn't actually what I mean. If you for example search on "gallery" on https://react-instantsearch.netlify.app/storybook/?path=/story/rangeinput--default you'll see that the min and max values of the range input change based on the given result.

Is there a way I'm able to do this with the Itemsjs library?

cigolpl commented 2 years ago

@Ruitjes ok, I see. You want to know i.e. min and max of field of the whole filtered dataset. I remind myself that one of the developer had similar issue and he patched it like that:

So I ended up adding a line to your library – after line 73 of itemsjs/src/lib.js, the “data” object of I added:: data: { items: filtered_items.slice((page - 1) per_page, page per_page), allFilteredItems: filtered_items, aggregations: aggregations }"

He just simply added allFilteredItems in search response and then he could make custom query on that array (i.e. with lodash or native js).

You can do this patch only in your code or you can make a PR and contribute to repository (should be simple)