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

[3.x] Facet group OR within AND accross groups #325

Merged
merged 16 commits into from
Nov 16, 2023

Conversation

andybroomfield
Copy link
Contributor

@andybroomfield andybroomfield commented Nov 10, 2023

This is a rebase of #235 and #269 onto the 3.x branch

Fix #193

Adds a new facet plugin to directories 'LocalGov Directories - AND Facet Groups' which when added to the directories facets will perform facet searches using an OR filter within a facet group and an AND filter accross the groups.

This includes the work needed to try to find all possible facets in a group, this is needed as facets only presents facets that are in the result set, but an OR facet in each group needs to check if they would be visible when the other facets apply an AND filter onto them.

Based on work by @snpower, @ekes and @andybroomfield

  • added 2 new facets plugins for processor and query_type. Together they provide a new pre_query processor on facets to AND facet groups together while still allowing OR within a facet group. This is based on initial code provided by Andy Broomfield
  • fixed coding style issues
  • coding style tweaks
  • Enable And/Or custom facet behaviour by default on Directories Facet.
  • Add a test for the facet And groups
  • Remove unneeded assertStatusCode
  • WIP Filter the facets so that the rest of the facets in group visible
  • Add function to fetch sibling facets that would be avalible
  • Coding standards.
  • Accept no deep clone, clarify what the code is doing.
  • Restore by reference for the conditions and fix for Drupal 10
  • Adds test for checking that correct facets are visible during selection
  • Coding standard fix on comments on the facet groups test
  • Reverse the facet group filter removing the passed in facet filter group

andybroomfield and others added 14 commits November 10, 2023 13:00
…y provide a new pre_query processor on facets to AND facet groups together while still allowing OR within a facet group. This is based on initial code provided by Andy Broomfield
This test creates 4 facets in two groups, and four directory entries in
a test directory channel.
It then tries to click on each facet, testing that the facets work
(in the default configuration) as OR facets within the group,
and AND facets accross the facet groups.
This will re run the query eliminating each group.
This is to address the issue in this comment
  #235 (comment)

Instead of just using the facets from the result set, re-run the query, each
time eliminating all the facets except each group, and filter out its own
so there is a list of each sibling facet that could be set with an OR that
also mathces an AND in the other group.
This then produces a filtered list of sibling facets that should be reachable
within the AND accross the groups and OR within them.
Just doing some minor cleanup while looking at the code.
The by refernece when fetching the conditions is required as otherwise
the resulting filters are not correctly applied for the new search.

Add the accessCheck(TRUE) to entityQueries.
Verifies that when facets are selected, facets that would offer a possible
selection are visible and not hidden. This occurs due to the way facets are
generated from the result set. Since each facet group is an OR, if there
are entries that could be shown by selecting OR in the group whilst
applying the AND filter from the other groups, they need to be selectable.

Adds a test to verify this with comments to help understand what is going on,
as this is a bit on the complicated side. What should happen is that in each
facet group, if after applying an AND filter from the other group, verify
that the correct facets are visible.

Eg. All facets from group 1 which would apply when facet 3 is selected, and all
facets from group 2 which would apply when facet 1 is selected, and then the
results are combined.
In the above case, facet 2 which is only assigned to content with facet 4
would be hidden as it would be inreachable.
Change the facet filters so that the we test the avalible facets by looping
through each facet group, removing that from the query and seeing what facets
from that group would be returned as an or filter. This is becuase going the
other way (removing the other groups) can lead to situations where possible
facets are removed.
@andybroomfield
Copy link
Contributor Author

This should be ready for review now.

Define $facetEntities as array and fix casing on $facetLabels
@finnlewis
Copy link
Member

Amazing @andybroomfield thank you!

I will find time to test.

@snpower sorry it has taken so long since your original pull request. Are you able to take a look at this reworked pull request and confirm it sill works for your use case?

// Execute the filter query and get the facets returned.
$filter_query->execute();
$facets = $filter_query->getResults()->getExtraData('search_api_facets');
// dpm($facets);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably wants to go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, thats done now.

Copy link
Member

@ekes ekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has updated changes that were possible from my previous review, so from that perspective all good.

We should probably document how complex the queries are getting, in comparison with using separate configuration facets.

@finnlewis
Copy link
Member

To test on local:

  • Install localgov_demo
  • edit localgov_direccories_facets
  • Check the AND Facet Groups option
  • Add some more facets to the organisations
  • The list should then or between facets within a facet and AND between the facets.

Copy link
Member

@finnlewis finnlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andybroomfield - I've tested locally and confirmed this works for me!

How I tested:

  1. Installed localgov_demo
  2. Added a new facet type 'Music' and new facet values to the /localgov-drupal-collaborators directory channel.
  3. Enabled the option:

image

  1. Confirmed that the facets are now OR'd within the facet group and AND'd between facet groups.

Nice!

@willguv willguv self-assigned this Nov 15, 2023
@andybroomfield
Copy link
Contributor Author

@finnlewis
Copy link
Member

@ekes sounded happy with this too.

I think we can merge and release this baby!

@finnlewis finnlewis merged commit 86de86d into 3.x Nov 16, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Use an 'and' query between facet groups and 'or' within them.
5 participants