Skip to content

Commit

Permalink
Merge pull request #273 from esmero/ISSUE-271
Browse files Browse the repository at this point in the history
ISSUE-271: Deal with Empty Queries on Advanced and Facet Summary for Queries
  • Loading branch information
DiegoPino authored Feb 14, 2023
2 parents eab97ad + 76bdb7f commit 2e5cc2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 2e5cc2a

Please sign in to comment.