File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 3
3
namespace Erichard \ElasticQueryBuilder \Query ;
4
4
5
5
use Erichard \ElasticQueryBuilder \Contracts \QueryInterface ;
6
+ use Erichard \ElasticQueryBuilder \Features \HasBoost ;
6
7
use Erichard \ElasticQueryBuilder \Features \HasMinimumShouldMatch ;
7
8
8
9
class SimpleQueryStringQuery implements QueryInterface
9
10
{
11
+ use HasBoost;
10
12
use HasMinimumShouldMatch;
11
13
12
14
/**
@@ -167,6 +169,7 @@ public function build(): array
167
169
}
168
170
169
171
$ this ->buildMinimumShouldMatchTo ($ data );
172
+ $ this ->buildBoostTo ($ data );
170
173
171
174
$ build = $ this ->params ;
172
175
$ build ['simple_query_string ' ] = $ data ;
Original file line number Diff line number Diff line change 4
4
5
5
namespace Tests \Erichard \ElasticQueryBuilder \Query ;
6
6
7
- use Erichard \ElasticQueryBuilder \Query \MultiMatchQuery ;
8
7
use Erichard \ElasticQueryBuilder \Query \SimpleQueryStringQuery ;
9
8
use PHPUnit \Framework \TestCase ;
10
9
@@ -94,4 +93,49 @@ public function testItBuildTheQueryWithAFuzziness(): void
94
93
],
95
94
], $ query ->build ());
96
95
}
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
+ }
97
141
}
You can’t perform that action at this time.
0 commit comments