k-samuel / faceted-search

PHP Faceted search library
MIT License
205 stars 14 forks source link

Bug in selfFiltering #37

Closed janroz closed 9 months ago

janroz commented 9 months ago

Hello Kirill,

I thing I found a bug.

When I have selfFiltering on, filters not returns counts for all possible params.

$filters[] = new ValueFilter('category', [1,4,5]);
$filters[] = new ValueIntersectionFilter('u', [10,12]);
$filters[] = new ValueFilter('mount', ['ABC', 'CDE']);

...

$query = (new AggregationQuery())->filters($filters)->countItems()->selfFiltering(true);

It works perfectly, it returns counts for all but not the categories that are not selected. Returns counts for category 1,4,5 but not others. When I select some other category, it returns counts for it, for example:

$filters[] = new ValueFilter('category', [1,4,5,6,7]);

it returns counts for 1,4,5,6,7.

I don't know if it is bug or feature. I tried to fix it, but without success. Can you please point me out?

k-samuel commented 9 months ago

Hello. Interesting. I’ll check it out.

k-samuel commented 9 months ago

Can you share data sample please? If category record has only one category value: $data= ['id'=>1,'category'=>1, ...], then it looks like self-filtering works properly. Results can not contain other categories because of filtering. Thats why self-filtering is disabled by default.

Try to disable self-filtering.

janroz commented 9 months ago

I'll prepare some samples for you today. I need a self-filtering mechanism, as I mentioned earlier, because certain parameters need to work together using an AND operator, not OR. I need to list records that have both X and Y, not records having either X or Y.

I will try to create some examples. I can send you a link to a website where this is implemented, but only in a private message. If you're interested, please contact me.

k-samuel commented 9 months ago

Shure. Please write me in FB (contacts on my profile)

k-samuel commented 9 months ago

Do I understand correctly that you would like to be able to enable self-filtering for specific filters and not for all ? Like this:

$filters[] = new ValueFilter('category', [1,4,5]);
$filters[] = (new ValueIntersectionFilter('u', [10,12]))->selfFiltering(true);
$filters[] = new ValueFilter('mount', ['ABC', 'CDE']);

...

$query = (new AggregationQuery())->filters($filters)->countItems();
janroz commented 9 months ago

Exactly!

k-samuel commented 9 months ago

Great, I'll try to implement it

k-samuel commented 9 months ago

Simple implementation is ready. You can test it in your case. https://github.com/k-samuel/faceted-search/pull/38 I haven’t had time to cover it well with tests yet. If it’s conceptually suitable, I’ll try to add test cases.

janroz commented 9 months ago

Kirill, it looks very good!

k-samuel commented 9 months ago

Added a couple of test cases. Didn't reveal any unexpected behavior. Please let me know that in your case everything works as expected. If everything is ok, I’ll make a minor release.

janroz commented 9 months ago

Hi, it works perfectly. I took a closer look at it today. Great job!

k-samuel commented 9 months ago

Released in 3.2.1