Skip to content

Commit 9529f40

Browse files
committed
Added HasBoost feature to SimpleQueryStringQuery
1 parent 6991875 commit 9529f40

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/Query/SimpleQueryStringQuery.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace Erichard\ElasticQueryBuilder\Query;
44

55
use Erichard\ElasticQueryBuilder\Contracts\QueryInterface;
6+
use Erichard\ElasticQueryBuilder\Features\HasBoost;
67
use Erichard\ElasticQueryBuilder\Features\HasMinimumShouldMatch;
78

89
class SimpleQueryStringQuery implements QueryInterface
910
{
11+
use HasBoost;
1012
use HasMinimumShouldMatch;
1113

1214
/**
@@ -167,6 +169,7 @@ public function build(): array
167169
}
168170

169171
$this->buildMinimumShouldMatchTo($data);
172+
$this->buildBoostTo($data);
170173

171174
$build = $this->params;
172175
$build['simple_query_string'] = $data;

tests/Query/SimpleQueryStringQueryTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Erichard\ElasticQueryBuilder\Query;
66

7-
use Erichard\ElasticQueryBuilder\Query\MultiMatchQuery;
87
use Erichard\ElasticQueryBuilder\Query\SimpleQueryStringQuery;
98
use PHPUnit\Framework\TestCase;
109

@@ -94,4 +93,49 @@ public function testItBuildTheQueryWithAFuzziness(): void
9493
],
9594
], $query->build());
9695
}
96+
97+
public function testItBuildTheQueryWithBoost(): void
98+
{
99+
$query = new SimpleQueryStringQuery(
100+
['subject', 'body'],
101+
'~brown fox',
102+
'ALL',
103+
true,
104+
50,
105+
0,
106+
"1%",
107+
"or",
108+
"standard",
109+
false,
110+
"",
111+
false,
112+
true
113+
114+
);
115+
$query->setBoost(3);
116+
117+
$this->assertEquals([
118+
'simple_query_string' =>
119+
[
120+
'query' => '~brown fox',
121+
'fields' =>
122+
[
123+
'subject',
124+
'body',
125+
],
126+
'flags' => 'ALL',
127+
'fuzzy_transpositions' => true,
128+
'fuzzy_max_expansions' => 50,
129+
'fuzzy_prefix_length' => 0,
130+
'default_operator' => 'or',
131+
'analyzer' => 'standard',
132+
'lenient' => false,
133+
'quote_field_suffix' => '',
134+
'analyze_wildcard' => false,
135+
'auto_generate_synonyms_phrase_query' => true,
136+
'minimum_should_match' => '1%',
137+
'boost' => 3,
138+
],
139+
], $query->build());
140+
}
97141
}

0 commit comments

Comments
 (0)