- 🇦🇹Austria tgoeg
Alright, this was haunting me for too long :-)
I know why this was only partially reproducible: It depends on whether or not you're logged in (and in the development phase I am more or less constantly logged in, so only seldomly saw this).
The problem is this:
When not logged it, there are more conditions/condition groups. Which makes the mentioned location in the code fail as another condition group needs to be unrolled.
The linked MR only made it worse in my case, as my (specific) query would not work anymore, neither logged in nor as an anonymous user.This was pretty hard, considering I am no (PHP) dev at all, however
dump(condition)
worked wonders.This is how the conditions look like in my case:
^ Drupal\search_api\Query\ConditionGroup {#7804 ▼ #conditions: array:2 [▼ 0 => Drupal\search_api\Query\ConditionGroup {#7564 ▼ #conditions: array:2 [▼ 0 => Drupal\search_api\Query\Condition {#7573 ▼ #field: "search_api_datasource" #value: "entity:file" #operator: "=" } 1 => Drupal\search_api\Query\ConditionGroup {#7561 ▼ #conditions: array:2 [▼ 0 => Drupal\search_api\Query\ConditionGroup {#7554 ▼ #conditions: array:1 [▼ 0 => Drupal\search_api\Query\Condition {#7341 ▼ #field: "status" #value: true #operator: "=" } ] #conjunction: "OR" #tags: array:1 [▶] } 1 => Drupal\search_api\Query\ConditionGroup {#7340 ▼ #conditions: array:2 [▼ 0 => Drupal\search_api\Query\Condition {#7338 ▼ #field: "node_grants" #value: "node_access_all:0" #operator: "=" } 1 => Drupal\search_api\Query\Condition {#7337 ▼ #field: "node_grants" #value: "node_access__all" #operator: "=" } ] #conjunction: "OR" #tags: array:1 [▶] } ] #conjunction: "AND" #tags: [] } ] #conjunction: "OR" #tags: array:1 [▶] } 1 => Drupal\search_api\Query\Condition {#7335 ▼ #field: "role_access" #value: array:1 [▼ 0 => "anonymous" ] #operator: "IN" } ] #conjunction: "AND" #tags: [] }
So a group of groups of groups of groups :-)
It seems to me this can be nested indefinitely and we don't know beforehand.That's why a recursive algorithm for unrolling the groups seems most adequate (and readable) to me.
It's even shorter than the original code.I pushed a change to the MR in https://www.drupal.org/project/search_api_meilisearch/issues/3322856 🐛 Custom filter groups on a View (Search API index view) are not working Fixed . This is my first commit ever, so I hope everything's in order. If not, please say so and I'll try to improve!
Any changes to the code welcome - I am just a sysadmin with some C background.
- Status changed to Closed: duplicate
over 1 year ago 8:08am 3 August 2023 - 🇸🇮Slovenia DeaOm
As you already mentioned this is handled in the 🐛 Custom filter groups on a View (Search API index view) are not working Fixed and you also added a commit there, I'm closing this as duplicate in favor of the related issue (better transparency).