Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] NotValueFilter and OutsideRangeFilter #26

Closed
Langmans opened this issue Jun 8, 2023 · 8 comments
Closed

[Feature request] NotValueFilter and OutsideRangeFilter #26

Langmans opened this issue Jun 8, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@Langmans
Copy link

Langmans commented Jun 8, 2023

Currently you can filter based on wether a record has a specific value. I'd like to be able to filter my records that do not have a specific value, so a NotValueFilter. Would this be in the scope of this library?

Same goes for the RangeFilter, maybe OutsideRangeFilter is a nice class name?

@k-samuel
Copy link
Owner

k-samuel commented Jun 8, 2023

Hello, this is an interesting case. Can you give an example of how this could be used in a real application?

I have a few ideas on how this could be done, I need the context in which it could be used.

The first and easiest option. If you have a third party data store. You can get a list of id that match the filter and query the database like Select from myTable where id NOT IN (reclist)

The second option is to get the full list of id from the library and find the difference with the list of those that have this value

The third option is to write additional functionality in the library, here i need to understand how it can be used.

Another important point. Do we want to know which products have a property not filled in, for example, weight, or do we want to know which products have weight not equal to X? (There is no value option / There are options but different)

@k-samuel k-samuel added the enhancement New feature or request label Jun 8, 2023
@Langmans
Copy link
Author

Langmans commented Jun 8, 2023

Thanks for the reply!

Can you give an example of how this could be used in a real application?

I'm looking at this from a user perspective, one that likes to finetune their search results. Let's say, I'm a potential amazon customer that is in need of a new laptop. But, I don't like to pay for a laptop with a very old screen (1024x768). Fine, so I select every resolution except 1024. But, when I select a resolution, the page is reloaded with AJAX. And there's like 10 resolutions. Takes some time... The more filters the customer the selects, the more he/she has to wait -> customer gets bored and leaves the site.

Wouldn't it be so much better to just add a small "exclude" button next to the checkbox? When you click it, the checkbox is grayed out, and all laptops are selected, except the ones with a 1024x768 resolution. You might need to wait the same time as when you checked everything except one value, but you only need to wait once.

The first and easiest option. If you have a third party data store. You can get a list of id that match the filter and query the database like Select from myTable where id NOT IN (reclist)

That could be a solution. So what you're saying, invert the excluded filters (ignoring the actually selected filters) then use the database to select the id's that aren't returned, then re-filter those id's again using the selected filters? The potential problem with this, is that it makes a roundtrip to the database. Depending on server load / database platform / database version, this could increase load time more then it would having a full featured solution using just PHP and OPCache / Redis / Memcached. I haven't tested this, so I can't be sure.

The second option is to get the full list of id from the library and find the difference with the list of those that have this value

I like this solution a bit better then combining your library with a database. But I wonder if it would make it more complicated then just using the database.

The third option is to write additional functionality in the library, here i need to understand how it can be used.

I think the best way to describe it is by looking at real world examples. A good example is https://mods.factorio.com/explore (mods for a game called factorio), you can see they removed mods with category "internal". The internal category holds library mods, and players don't usually only install library mods (they are required for other mods, but don't do anything by themselves).

Another example is all mods that have the tag "train", they also usually have a tag "transportation" (as it would make sense). But let's say I want transportation methods other then trains, because in real life trains in my country are always late and I prefer using my car, so I exclude trains ( 😂 ).

To describe it as SQL, when you have a pivot view for a record / EAV table (tags is a column where GROUP_CONCAT is used with pipeline as seperator):

select mods_view.* from mods_view where tags like "%|train|%" and tags not like "%|transportation|%".

Another important point. Do we want to know which products have a property not filled in, for example, weight, or do we want to know which products have weight not equal to X? (There is no value option / There are options but different)

So null vs not null. That is totally up to you. As for technical discussion: array indexes can't be NULL, so maybe using string "null" as a key?

As for logic discussion, I think it's fine to have programming logic outside the library to hide and ignore a specific filter with values if another value filter has a certain key set. For example, your store offers services and physical products, so you add a filter "product type" (physical product / service). A weight filter is then completely ignored and hidden or disabled if a user filters "service" only. Another example: your store sells products with or without extended warranty. You would have 2 filters, "extended warranty possible"(yes/no) and "extended warranty years" (2,3,4,5). Extended warranty years would then be ignored and hidden / disabled if a user hasn't selected yes for "extended warranty possible".

Not having something automatic like that in your library is completely agreeable IMHO. It's just not possible since you are not AI.

P.S. I hope my reply is not too long :D

@k-samuel
Copy link
Owner

k-samuel commented Jun 9, 2023

I like the idea. I'll try to make an experimental implementation this weekend.
Most likely this will require tinkering with performance issues and inventing tricks with optimizations
As far as I understand, we need something like ExceptValueFilter/ ExceptRangeFilter

@k-samuel k-samuel mentioned this issue Jun 9, 2023
@k-samuel
Copy link
Owner

It looks like the first version has been implemented. Haven't done any deep performance optimization yet.
You would help me a lot if you looked and tested the branch https://github.com/k-samuel/faceted-search/tree/3.1.0_unsets

The easiest way to see the changes is to clone the branch and run the Demo from the examples folder (mobile catalog).

PR: #27

@Langmans
Copy link
Author

Didn't expect to see new code so soon. You've been busy 😲 From what I can see in the src dir it's exactly what I described! Will check the examples and let you know if I have any ideas.

@k-samuel
Copy link
Owner

Available in 3.1.0

@Langmans
Copy link
Author

I just wanted to thank you again. Your library is the only one at the moment that isn't tied to external services (elastic search, apache sol, sphinx) or part of monolithic packages(symfony/laravel) so it makes it very easy to develop sites as a third party. I can not think of any other missing backend functionality right now 👍

@k-samuel
Copy link
Owner

Thanks for your feedback. I hope the library will help you and simplify the solution of your tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants