Loading CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3392465 by drunken monkey: Fixed use of location filter together with AND facets in DB backend. - #3293474 by admirlju, jhedstrom, drunken monkey: Added configurable maximum length for exposed Views fulltext filter. Loading modules/search_api_db/src/Plugin/search_api/backend/Database.php +9 −1 Original line number Diff line number Diff line Loading @@ -2872,7 +2872,7 @@ class Database extends BackendPluginBase implements AutocompleteBackendInterface return FALSE; } $expressions = &$db_query->getExpressions(); $expressions = []; unset($expressions['score']); // Remove the ORDER BY clause, as it may refer to expressions that are // unset above. Loading @@ -2884,11 +2884,19 @@ class Database extends BackendPluginBase implements AutocompleteBackendInterface $group_by = &$db_query->getGroupBy(); $group_by = array_intersect_key($group_by, ['t.item_id' => TRUE]); // In case there are any expressions left (like a computed distance column), // we nest the query to get rid of them. if ($expressions) { $db_query = $this->database->select($db_query, 't') ->fields('t', ['item_id']); } $db_query->distinct(); if (!$db_query->preExecute()) { return FALSE; } $args = $db_query->getArguments(); try { $result = $this->database->queryTemporary((string) $db_query, $args); } Loading modules/search_api_db/tests/src/Kernel/LocationTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,15 @@ class LocationTest extends BackendTestBase { $query = $this->buildSearch(place_id_sort: FALSE)->sort('location__distance'); $query->setOption('search_api_location', $location_options); $query->setOption('search_api_retrieved_field_values', ['location__distance' => 'location__distance']); // Also add a facet, since that used to lead to a PDO exception. $facets['category'] = [ 'field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE, 'operator' => 'and', ]; $query->setOption('search_api_facets', $facets); $result = $query->execute(); $this->assertResults([3, 1], $result, 'Search for 500km from Antwerp ordered by distance'); Loading @@ -152,6 +161,8 @@ class LocationTest extends BackendTestBase { ->sort('location__distance', 'DESC'); $query->setOption('search_api_location', $location_options); // Also add a facet, since that used to lead to a PDO exception. $query->setOption('search_api_facets', $facets); $result = $query->execute(); $this->assertResults([2, 1], $result, 'Search between 100 and 6000km from Antwerp ordered by distance descending'); } Loading tests/src/Kernel/BackendTestBase.php +24 −4 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ abstract class BackendTestBase extends KernelTestBase { */ protected function checkFacets() { $query = $this->buildSearch(); $conditions = $query->createAndAddConditionGroup('OR', ['facet:' . 'category']); $conditions = $query->createAndAddConditionGroup('OR', ['facet:category']); $conditions->addCondition('category', 'article_category'); $facets['category'] = [ 'field' => 'category', Loading @@ -412,10 +412,10 @@ abstract class BackendTestBase extends KernelTestBase { ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Correct OR facets were returned'); $this->assertEquals($expected, $category_facets, 'Incorrect OR facets were returned'); $query = $this->buildSearch(); $conditions = $query->createAndAddConditionGroup('OR', ['facet:' . 'category']); $conditions = $query->createAndAddConditionGroup('OR', ['facet:category']); $conditions->addCondition('category', 'article_category'); $conditions = $query->createAndAddConditionGroup(); $conditions->addCondition('category', NULL, '<>'); Loading @@ -435,7 +435,27 @@ abstract class BackendTestBase extends KernelTestBase { ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Correct OR facets were returned'); $this->assertEquals($expected, $category_facets, 'Incorrect OR facets were returned'); $query = $this->buildSearch(); $query->createAndAddConditionGroup('OR', ['facet:category']) ->addCondition('category', 'article_category'); $facets['category'] = [ 'field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE, 'operator' => 'and', ]; $query->setOption('search_api_facets', $facets); $results = $query->execute(); $this->assertResults([4, 5], $results, 'AND facets query'); $expected = [ ['count' => 2, 'filter' => '"article_category"'], ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Incorrect AND facets were returned'); } /** Loading Loading
CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3392465 by drunken monkey: Fixed use of location filter together with AND facets in DB backend. - #3293474 by admirlju, jhedstrom, drunken monkey: Added configurable maximum length for exposed Views fulltext filter. Loading
modules/search_api_db/src/Plugin/search_api/backend/Database.php +9 −1 Original line number Diff line number Diff line Loading @@ -2872,7 +2872,7 @@ class Database extends BackendPluginBase implements AutocompleteBackendInterface return FALSE; } $expressions = &$db_query->getExpressions(); $expressions = []; unset($expressions['score']); // Remove the ORDER BY clause, as it may refer to expressions that are // unset above. Loading @@ -2884,11 +2884,19 @@ class Database extends BackendPluginBase implements AutocompleteBackendInterface $group_by = &$db_query->getGroupBy(); $group_by = array_intersect_key($group_by, ['t.item_id' => TRUE]); // In case there are any expressions left (like a computed distance column), // we nest the query to get rid of them. if ($expressions) { $db_query = $this->database->select($db_query, 't') ->fields('t', ['item_id']); } $db_query->distinct(); if (!$db_query->preExecute()) { return FALSE; } $args = $db_query->getArguments(); try { $result = $this->database->queryTemporary((string) $db_query, $args); } Loading
modules/search_api_db/tests/src/Kernel/LocationTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,15 @@ class LocationTest extends BackendTestBase { $query = $this->buildSearch(place_id_sort: FALSE)->sort('location__distance'); $query->setOption('search_api_location', $location_options); $query->setOption('search_api_retrieved_field_values', ['location__distance' => 'location__distance']); // Also add a facet, since that used to lead to a PDO exception. $facets['category'] = [ 'field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE, 'operator' => 'and', ]; $query->setOption('search_api_facets', $facets); $result = $query->execute(); $this->assertResults([3, 1], $result, 'Search for 500km from Antwerp ordered by distance'); Loading @@ -152,6 +161,8 @@ class LocationTest extends BackendTestBase { ->sort('location__distance', 'DESC'); $query->setOption('search_api_location', $location_options); // Also add a facet, since that used to lead to a PDO exception. $query->setOption('search_api_facets', $facets); $result = $query->execute(); $this->assertResults([2, 1], $result, 'Search between 100 and 6000km from Antwerp ordered by distance descending'); } Loading
tests/src/Kernel/BackendTestBase.php +24 −4 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ abstract class BackendTestBase extends KernelTestBase { */ protected function checkFacets() { $query = $this->buildSearch(); $conditions = $query->createAndAddConditionGroup('OR', ['facet:' . 'category']); $conditions = $query->createAndAddConditionGroup('OR', ['facet:category']); $conditions->addCondition('category', 'article_category'); $facets['category'] = [ 'field' => 'category', Loading @@ -412,10 +412,10 @@ abstract class BackendTestBase extends KernelTestBase { ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Correct OR facets were returned'); $this->assertEquals($expected, $category_facets, 'Incorrect OR facets were returned'); $query = $this->buildSearch(); $conditions = $query->createAndAddConditionGroup('OR', ['facet:' . 'category']); $conditions = $query->createAndAddConditionGroup('OR', ['facet:category']); $conditions->addCondition('category', 'article_category'); $conditions = $query->createAndAddConditionGroup(); $conditions->addCondition('category', NULL, '<>'); Loading @@ -435,7 +435,27 @@ abstract class BackendTestBase extends KernelTestBase { ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Correct OR facets were returned'); $this->assertEquals($expected, $category_facets, 'Incorrect OR facets were returned'); $query = $this->buildSearch(); $query->createAndAddConditionGroup('OR', ['facet:category']) ->addCondition('category', 'article_category'); $facets['category'] = [ 'field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE, 'operator' => 'and', ]; $query->setOption('search_api_facets', $facets); $results = $query->execute(); $this->assertResults([4, 5], $results, 'AND facets query'); $expected = [ ['count' => 2, 'filter' => '"article_category"'], ]; $category_facets = $results->getExtraData('search_api_facets')['category']; usort($category_facets, [$this, 'facetCompare']); $this->assertEquals($expected, $category_facets, 'Incorrect AND facets were returned'); } /** Loading