- Issue created by @ekes
- π³π±Netherlands ekes
I can add:
I did try and write a (failing) test for this. There don't seem to be any tests for AND facets in search_api/tests at least, only OR? When I tried adding an AND facet in a Kernel test something like
// Search with a AND facet. $location_options = [ [ 'field' => 'location', 'lat' => '51.260197', 'lon' => '4.402771', 'radius' => '500', ], ]; $query = $this->buildSearch(place_id_sort: FALSE)->sort('location__distance'); $query->setOption('search_api_location', $location_options); $conditions = $query->createAndAddConditionGroup('AND', ['facet:' . 'category']); $conditions->addCondition('category', 'item_category'); $facets['category'] = [ 'field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE, 'operator' => 'and', ]; $query->setOption('search_api_facets', $facets); $results = $query->execute();
I ended up with a
PHPUnit\Framework\Exception: PHP Fatal error: Uncaught AssertionError: The container was serialized. in /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php:88
- π¬π§United Kingdom Finn Lewis
Finn Lewis β made their first commit to this issueβs fork.
- π¬π§United Kingdom Finn Lewis
I can confirm the behaviour on my local dev environment.
I've created an issue fork and a commit that I can use as a patch for now to test hacking those two lines out of search_api_db.
https://git.drupalcode.org/issue/search_api-3392465/-/commit/de1cc3c5d4a...
I really don't understand what is happening here, but looking back in time, those lines come from the Drupal 7 version of search_api_db 10 years ago, possibly around removing the score?
https://git.drupalcode.org/project/search_api_db/-/blame/7.x-1.x/service...
https://git.drupalcode.org/project/search_api_db/-/blob/7.x-1.0-rc1/serv...
https://git.drupalcode.org/project/search_api_db/-/commit/5aee9c0c63a08c...
- π³π±Netherlands ekes
The logic has always been there since facet support was first introduced https://git.drupalcode.org/project/search_api_db/-/commit/275c74c6b6ebb4... although there it seems even clearer the purpose is to keep conditions and even sorts (which would in postgres later add another field iirc), so it's just removing unnecessary fields (like score... are there others?)
- Status changed to Needs review
9 months ago 1:02pm 15 October 2023 - last update
9 months ago 545 pass - last update
9 months ago 545 pass - π¦πΉAustria drunken monkey Vienna, Austria
Thanks for reporting this problem!
I could easily reproduce it, the attached patch should fix it.
I also had no problem with writing a test, not sure what went wrong for you. You are right, in any case, that it is pretty weird that we donβt include any test forAND
facets, so I also fixed that (even though pretty out of scope, of course β sorry!). - last update
8 months ago 543 pass, 2 fail - last update
8 months ago 544 pass -
drunken monkey β
committed 4c20bcc0 on 8.x-1.x
Issue #3392465 by drunken monkey: Fixed use of location filter together...
-
drunken monkey β
committed 4c20bcc0 on 8.x-1.x
- Status changed to Fixed
8 months ago 4:20pm 21 October 2023 - π¦πΉAustria drunken monkey Vienna, Austria
Great, thanks for reporting back!
Merged. Thanks again! Automatically closed - issue fixed for 2 weeks with no activity.