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 33namespace Erichard \ElasticQueryBuilder \Query ;
44
55use Erichard \ElasticQueryBuilder \Contracts \QueryInterface ;
6+ use Erichard \ElasticQueryBuilder \Features \HasBoost ;
67use Erichard \ElasticQueryBuilder \Features \HasMinimumShouldMatch ;
78
89class 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 ;
Original file line number Diff line number Diff line change 44
55namespace Tests \Erichard \ElasticQueryBuilder \Query ;
66
7- use Erichard \ElasticQueryBuilder \Query \MultiMatchQuery ;
87use Erichard \ElasticQueryBuilder \Query \SimpleQueryStringQuery ;
98use 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}
You can’t perform that action at this time.
0 commit comments