Skip to content

Commit

Permalink
Do not add empty query (#296)
Browse files Browse the repository at this point in the history
* Do not add empty query

* Update changelog
  • Loading branch information
hulkur authored Jan 5, 2025
1 parent 74e1a37 commit c4cdd6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/)

## [Unreleased]

- FIX: SearchFactory adds empty `query_string` query even if query string is empty when no `where` clauses are set.

## [7.10.0] - 2024-12-128
### Added
Expand Down
7 changes: 3 additions & 4 deletions src/ElasticSearch/SearchFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ public static function create(Builder $builder, array $enforceOptions = []): Sea
{
$options = static::prepareOptions($builder, $enforceOptions);
$search = new Search();
$query = new QueryStringQuery($builder->query);
if (static::hasWhereFilters($builder)) {
$boolQuery = new BoolQuery();
$boolQuery = static::addWheres($builder, $boolQuery);
$boolQuery = static::addWhereIns($builder, $boolQuery);
$boolQuery = static::addWhereNotIns($builder, $boolQuery);
if (! empty($builder->query)) {
$boolQuery->add($query, BoolQuery::MUST);
$boolQuery->add(new QueryStringQuery($builder->query));
}
$search->addQuery($boolQuery);
} else {
$search->addQuery($query);
} elseif (! empty($builder->query)) {
$search->addQuery(new QueryStringQuery($builder->query));
}
if (array_key_exists('from', $options)) {
$search->setFrom($options['from']);
Expand Down

0 comments on commit c4cdd6c

Please sign in to comment.