From 5d7977f15d6e5590469edd016a63d73cdb51e524 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Mon, 13 Feb 2023 21:33:01 -0300 Subject: [PATCH 1/2] Double check if query did not fail (should not but...) And remove empties from Facet Queries. --- .../processor/LastActiveFacetsProcessor.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/format_strawberryfield_facets/src/Plugin/facets_summary/processor/LastActiveFacetsProcessor.php b/modules/format_strawberryfield_facets/src/Plugin/facets_summary/processor/LastActiveFacetsProcessor.php index 9ff5622a..3db20b19 100644 --- a/modules/format_strawberryfield_facets/src/Plugin/facets_summary/processor/LastActiveFacetsProcessor.php +++ b/modules/format_strawberryfield_facets/src/Plugin/facets_summary/processor/LastActiveFacetsProcessor.php @@ -47,7 +47,7 @@ public function build(FacetsSummaryInterface $facets_summary, array $build, arra ); } - if ($results_count == 0) { + if ($results_count == 0 && $results_query) { $results = []; foreach ($facets as $facet) { $build_stage_processors = $facet->getProcessorsByStage(ProcessorInterface::STAGE_BUILD); @@ -125,7 +125,7 @@ public function build(FacetsSummaryInterface $facets_summary, array $build, arra } } - if ($config['settings']['enable_query'] ?? FALSE) { + if ($config['settings']['enable_query'] ?? FALSE && $results_query) { // The original View /** @var \Drupal\views\ViewExecutable $view */ $view = $results_query->getQuery()->getOptions()['search_api_view']; @@ -231,20 +231,24 @@ public function build(FacetsSummaryInterface $facets_summary, array $build, arra if (in_array($key, $keys_to_filter)) { $search_term = NULL; if (in_array($key, $key_with_search_value)) { - $search_term = $exposed_input[$key] ?? NULL; - $search_terms[] = $search_term !== NULL ? '"'.$search_term.'"' : NULL; + $search_terms[] = $exposed_input[$key] ?? NULL; } unset($params[$key]); } } - $search_terms = array_filter($search_terms); + $search_terms = array_filter($search_terms, function ($element) { + return ((is_string($element) && '' !== trim($element)) || is_numeric($element)); + }); + if (count($search_terms)) { $url_active->setOption('query', $params); $item = [ '#theme' => 'facets_result_item__summary', - '#value' => implode(" ", $search_terms), + '#value' => implode(" ", array_map(function($string) { + return '"' . $string . '"'; + }, $search_terms)), '#show_count' => FALSE, '#count' => 0, '#is_active' => TRUE, From 76bdb7f27c6b4d9e8aa6cb5a3bd98b1ef5464789 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Mon, 13 Feb 2023 21:35:29 -0300 Subject: [PATCH 2/2] Direct Parser *bad drupal* dislikes empties So we discard empties... but we keep the untrimmed if the trim is not emtpy... --- .../src/Plugin/views/filter/AdvancedSearchApiFulltext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/format_strawberryfield_views/src/Plugin/views/filter/AdvancedSearchApiFulltext.php b/modules/format_strawberryfield_views/src/Plugin/views/filter/AdvancedSearchApiFulltext.php index bd8833cc..5df6db82 100644 --- a/modules/format_strawberryfield_views/src/Plugin/views/filter/AdvancedSearchApiFulltext.php +++ b/modules/format_strawberryfield_views/src/Plugin/views/filter/AdvancedSearchApiFulltext.php @@ -211,7 +211,7 @@ public function query() { foreach ($this->value as $exposed_value_id => $exposed_value) { // Catch empty strings entered by the user, but not "0". - if ($exposed_value === '') { + if (trim($exposed_value) === '') { unset($this->value[$exposed_value_id]); unset($this->searchedFields[$exposed_value_id]); }