From 93201162908c1e4001794a860b74688129b18e67 Mon Sep 17 00:00:00 2001 From: Amy Li Date: Mon, 13 Mar 2023 16:03:03 -0400 Subject: [PATCH 1/2] Query string becomes malformed when using 'is not' with Edismax enabled --- src/AdvancedSearchQuery.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AdvancedSearchQuery.php b/src/AdvancedSearchQuery.php index a072831..694d003 100644 --- a/src/AdvancedSearchQuery.php +++ b/src/AdvancedSearchQuery.php @@ -160,9 +160,11 @@ class AdvancedSearchQuery { $isSearchAllFields = false; $fields_list = []; + if (!$isDismax) { + // To support negative queries we must first bring in all documents. + $q[] = $this->negativeQuery($terms) ? "*:*" : ""; + } - // To support negative queries we must first bring in all documents. - $q[] = $this->negativeQuery($terms) ? "*:*" : ""; $term = array_shift($terms); $q[] = $term->toSolrQuery($field_mapping); From 9625a0a6a734334af4b90d47e167276af75c4322 Mon Sep 17 00:00:00 2001 From: Amy Li Date: Tue, 14 Mar 2023 10:38:31 -0400 Subject: [PATCH 2/2] Fix 'is not' search not working for keywords containing more than one word --- src/AdvancedSearchQueryTerm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AdvancedSearchQueryTerm.php b/src/AdvancedSearchQueryTerm.php index 161fc3b..ab9db12 100644 --- a/src/AdvancedSearchQueryTerm.php +++ b/src/AdvancedSearchQueryTerm.php @@ -302,7 +302,8 @@ class AdvancedSearchQueryTerm { return $value; } else { - return "(" .$value . " OR " . str_replace('"', "", trim($value)) . ")"; + $isNot = $this->getInclude() ? "" : "!"; + return $isNot . "(" .$value . " OR " . str_replace('"', "", trim($value)) . ")"; } } if (!$this->getInclude()) {