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

How to get count for each filter? #2

Closed
pixobit opened this issue May 20, 2021 · 7 comments
Closed

How to get count for each filter? #2

pixobit opened this issue May 20, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@pixobit
Copy link

pixobit commented May 20, 2021

I'm looking to achieve the result in this post https://stackoverflow.com/questions/35418885/multi-select-faceting-in-mysql-how-to-ignore-any-constraints-on-a-facet

@k-samuel
Copy link
Owner

k-samuel commented May 21, 2021

You can use

$filterData = $search->findAcceptableFilters($filters);

It returns only acceptable filters:

=== Size === === Color === === Brand ===
[Small] (0) [ ] Red (v) [ ] Nike (v)
[Medium] (v) [ ] Blue (v) [ ] Adidas (v)
[Large] (v) [x] Black (v) [ ] Reebok (v)

Not

=== Size === === Color === === Brand ===
[Small] (0) [ ] Red (1) [ ] Nike (1)
[Medium] (1) [ ] Blue (1) [ ] Adidas (2)
[Large] (1) [x] Black (2) [ ] Reebok (1)

I think I can update the library to solve your case. If you realy need this.
Another solution is to use ElasticSearch Aggregations.

@pixobit
Copy link
Author

pixobit commented May 21, 2021

That's really good actually. But getting the counts would be the final goal.
Unfortunatelly ElasticSearch is not an option, as it needs to be working on a shared hosting...

Great job by the way!

@k-samuel
Copy link
Owner

Already done, give me a few hours to test

@k-samuel
Copy link
Owner

Implemented in 1.2.5 https://github.com/k-samuel/faceted-search/releases/tag/1.2.5

// If you want to get acceptable filters values with items count use findAcceptableFiltersCount
// note that filters is not applied for itself for counting
// values count of a particular field depends only on filters imposed on other fields 
$filterData = $search->findAcceptableFiltersCount($filters);

@pixobit
Copy link
Author

pixobit commented May 21, 2021

That's awesome! Will play around with it over the weekend.
Thanks!

@pixobit
Copy link
Author

pixobit commented May 21, 2021

If an item has multiple attributes of the same type, for ex. ["id"=>1,"color"=>["Black","White"]], do they need to be separate entries under the same "id"? or it's possible to directly pass an array?

@k-samuel
Copy link
Owner

k-samuel commented May 21, 2021

Multiple attributes can be set as an array ["id"=>1,"color"=>["Black","White"]], its ok

@k-samuel k-samuel added the enhancement New feature or request label May 22, 2021
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