From d5fc900baa73dba134079594a19a436208779df8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 13 Mar 2024 11:38:36 +0100 Subject: [PATCH] Only qualify base columns during quick searches All other columns are already qualified relative to the base model. This is usually sufficient because qualification is only required if applied to a query, which isn't happening at this stage. fixes #979 --- .../Icingadb/Web/Control/SearchBar/ObjectSuggestions.php | 8 ++++++-- library/Icingadb/Web/Controller.php | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index b89e72919..31b6483cd 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -121,8 +121,12 @@ protected function createQuickSearchFilter($searchTerm) $quickFilter = Filter::any(); foreach ($model->getSearchColumns() as $column) { - $where = Filter::like($resolver->qualifyColumn($column, $model->getTableName()), $searchTerm); - $where->metaData()->set('columnLabel', $resolver->getColumnDefinition($where->getColumn())->getLabel()); + if (strpos($column, '.') === false) { + $column = $resolver->qualifyColumn($column, $model->getTableName()); + } + + $where = Filter::like($column, $searchTerm); + $where->metaData()->set('columnLabel', $resolver->getColumnDefinition($column)->getLabel()); $quickFilter->add($where); } diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index ad9f07ee2..91b28a044 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -307,10 +307,11 @@ protected function prepareSearchFilter(Query $query, string $search, Filter\Any { $columns = array_merge($query->getModel()->getSearchColumns(), $additionalColumns); foreach ($columns as $column) { - $filter->add(Filter::like( - $query->getResolver()->qualifyColumn($column, $query->getModel()->getTableName()), - "*$search*" - )); + if (strpos($column, '.') === false) { + $column = $query->getResolver()->qualifyColumn($column, $query->getModel()->getTableName()); + } + + $filter->add(Filter::like($column, "*$search*")); } }