Skip to content

Commit

Permalink
Added HasBoost feature to SimpleQueryStringQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilyes512 committed Jan 16, 2024
1 parent 6991875 commit 9529f40
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Query/SimpleQueryStringQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -167,6 +169,7 @@ public function build(): array
}

$this->buildMinimumShouldMatchTo($data);
$this->buildBoostTo($data);

$build = $this->params;
$build['simple_query_string'] = $data;
Expand Down
46 changes: 45 additions & 1 deletion tests/Query/SimpleQueryStringQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Erichard\ElasticQueryBuilder\Query;

use Erichard\ElasticQueryBuilder\Query\MultiMatchQuery;
use Erichard\ElasticQueryBuilder\Query\SimpleQueryStringQuery;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -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());
}
}

0 comments on commit 9529f40

Please sign in to comment.