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); 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()) {