diff --git a/src/Query/SimpleQueryStringQuery.php b/src/Query/SimpleQueryStringQuery.php index a39e076..c832a47 100644 --- a/src/Query/SimpleQueryStringQuery.php +++ b/src/Query/SimpleQueryStringQuery.php @@ -3,10 +3,12 @@ namespace Erichard\ElasticQueryBuilder\Query; use Erichard\ElasticQueryBuilder\Contracts\QueryInterface; +use Erichard\ElasticQueryBuilder\Features\HasBoost; use Erichard\ElasticQueryBuilder\Features\HasMinimumShouldMatch; class SimpleQueryStringQuery implements QueryInterface { + use HasBoost; use HasMinimumShouldMatch; /** @@ -167,6 +169,7 @@ public function build(): array } $this->buildMinimumShouldMatchTo($data); + $this->buildBoostTo($data); $build = $this->params; $build['simple_query_string'] = $data; diff --git a/tests/Query/SimpleQueryStringQueryTest.php b/tests/Query/SimpleQueryStringQueryTest.php index 4727cdf..f7bc6a3 100644 --- a/tests/Query/SimpleQueryStringQueryTest.php +++ b/tests/Query/SimpleQueryStringQueryTest.php @@ -4,7 +4,6 @@ namespace Tests\Erichard\ElasticQueryBuilder\Query; -use Erichard\ElasticQueryBuilder\Query\MultiMatchQuery; use Erichard\ElasticQueryBuilder\Query\SimpleQueryStringQuery; use PHPUnit\Framework\TestCase; @@ -94,4 +93,49 @@ public function testItBuildTheQueryWithAFuzziness(): void ], ], $query->build()); } + + public function testItBuildTheQueryWithBoost(): void + { + $query = new SimpleQueryStringQuery( + ['subject', 'body'], + '~brown fox', + 'ALL', + true, + 50, + 0, + "1%", + "or", + "standard", + false, + "", + false, + true + + ); + $query->setBoost(3); + + $this->assertEquals([ + 'simple_query_string' => + [ + 'query' => '~brown fox', + 'fields' => + [ + 'subject', + 'body', + ], + 'flags' => 'ALL', + 'fuzzy_transpositions' => true, + 'fuzzy_max_expansions' => 50, + 'fuzzy_prefix_length' => 0, + 'default_operator' => 'or', + 'analyzer' => 'standard', + 'lenient' => false, + 'quote_field_suffix' => '', + 'analyze_wildcard' => false, + 'auto_generate_synonyms_phrase_query' => true, + 'minimum_should_match' => '1%', + 'boost' => 3, + ], + ], $query->build()); + } }