itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request - min and max values

Ruitjes opened this issue · comments

commented

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?

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

commented

@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?

@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)