Hey! I'm trying to use negative filter with numeri...
# community-help
a
Hey! I'm trying to use negative filter with numeric values for example: (filter:!=[1..n]) Using the range widget I can have that type of filter set but can't figure out how to negate it instead I noticed in the search adapter there's a section that takes care of adapting the numeric filters: _adaptNumericFilters I'm wondering is that the best place to work on this or is there another way to achieve this I haven't seen yet. Any help is appreciated!
j
I don’t think the range widget in instantsearch allows you to have range exclusions… at least afaik
So you might have to build a custom widget for this
a
thanks for quick reply! while the range is positive numbers I want to exclude results that contain that range.
j
Yeah sorry, that’s what I meant to say. Edited my first reply
a
ok I'll keep looking! thanks
Hey so I asked on the instantsearch github and they basically said this is not supported to do the opposite filter filter:<=smallest filter:>=largest doing that I noticed I could change the filter applied in SearchRequestAdapter like this
if (filtersHash[field]["<="] != null && filtersHash[field][">="] != null && (filtersHash[field]["<="] > filtersHash[field][">="])) {
adaptedFilters.push("".concat(field, ":=[").concat(filtersHash[field][">="], "..").concat(filtersHash[field]["<="], "]"));
} else if (filtersHash[field]["<="] != null && filtersHash[field][">="] != null) {
adaptedFilters.push("".concat(field, ":!=[").concat(filtersHash[field]["<="], "..").concat(filtersHash[field][">="], "]"));
do you have any opinions on this or any better way? thank you!
j
Hmmmm, interesting approach... But may be another thing you could do is accept a config option when instantiating the adapter, that you can check in this method to then use
:!=
when that flag is enabled. May be the flag is called something like
negateNumericRanges
for eg
a
great ok, would this be something more people would want to use I can submit a pr if so otherwise I guess the best thing to do is fork and build our own internal version? maybe there could be some way to insert custom parser to avoid having to keep a personal version
j
This is the first time I've seen an ask like this, so I'm hesitant to add it into the library yet. But if you're down for it, could you still open a PR? We can leave it open in case anyone else needs it, and if there's sufficient demand, we can merge it later
a
sounds good maybe there is a better way to solve this that's why I'm not sure if it merits a pr but it seems like something other people might want to do. thanks for your input and help
👍 1
submitted a pr here in case anyone else is trying to do something similar! https://github.com/typesense/typesense-instantsearch-adapter/pull/203
👍 1