@@ -18,42 +18,42 @@ trait QueryBuilder
1818
1919 protected static $ equivalenceOperators = ['in ' , 'nin ' ];
2020
21- protected static $ clauseOperators = ['ne ' , 'gt ' , 'gte ' , 'lt ' , 'lte ' , 'between ' , 'not_between ' , 'like ' , 'not_like ' , 'exists ' ,'regex ' ];
21+ protected static $ clauseOperators = ['ne ' , 'gt ' , 'gte ' , 'lt ' , 'lte ' , 'between ' , 'not_between ' , 'like ' , 'not_like ' , 'exists ' , 'regex ' ];
2222
2323
2424 //======================================================================
2525 // Parameter builders
2626 //======================================================================
2727
28- public static function buildSearchParams ($ index , $ searchQuery , $ searchOptions ,$ wheres = [],$ options = [],$ fields = [],$ columns = [])
28+ public static function buildSearchParams ($ index , $ searchQuery , $ searchOptions , $ wheres = [], $ options = [], $ fields = [], $ columns = [])
2929 {
3030 $ params = [];
31- if ($ index ){
31+ if ($ index ) {
3232 $ params ['index ' ] = $ index ;
3333 }
3434 $ params ['body ' ] = [];
3535
3636
3737 $ queryString ['query ' ] = $ searchQuery ;
38- if ($ wheres ){
38+ if ($ wheres ) {
3939 $ wheres = self ::_buildQuery ($ wheres );
4040 $ whereQueryString = $ wheres ['query ' ]['query_string ' ]['query ' ] ?? null ;
41- if ($ whereQueryString ){
41+ if ($ whereQueryString ) {
4242 $ queryString ['query ' ] = '( ' .$ searchQuery .') AND ' .$ whereQueryString ;
4343 }
4444 }
4545
46- if ($ fields ){
46+ if ($ fields ) {
4747 $ queryString ['fields ' ] = [];
48- foreach ($ fields as $ field => $ boostLevel ){
49- if ($ boostLevel > 1 ){
48+ foreach ($ fields as $ field => $ boostLevel ) {
49+ if ($ boostLevel > 1 ) {
5050 $ field = $ field .'^ ' .$ boostLevel ;
5151 }
5252 $ queryString ['fields ' ][] = $ field ;
5353 }
5454 }
55- if ($ searchOptions ){
56- foreach ($ searchOptions as $ searchOption => $ searchOptionValue ){
55+ if ($ searchOptions ) {
56+ foreach ($ searchOptions as $ searchOption => $ searchOptionValue ) {
5757 $ queryString [$ searchOption ] = $ searchOptionValue ;
5858 }
5959 }
@@ -63,7 +63,7 @@ public static function buildSearchParams($index, $searchQuery, $searchOptions,$w
6363 if ($ columns && $ columns != '* ' ) {
6464 $ params ['body ' ]['_source ' ] = $ columns ;
6565 }
66- if ($ options ){
66+ if ($ options ) {
6767 $ opts = self ::_buildOptions ($ options );
6868 if ($ opts ) {
6969 foreach ($ opts as $ key => $ value ) {
@@ -75,17 +75,18 @@ public static function buildSearchParams($index, $searchQuery, $searchOptions,$w
7575 }
7676 }
7777 }
78- if (self ::$ filter ){
78+ if (self ::$ filter ) {
7979 $ params = self ::_parseFilterParameter ($ params , self ::$ filter );
8080 }
81+
8182 return $ params ;
8283 }
8384
8485 public static function buildParams ($ index , $ wheres , $ options = [], $ columns = [], $ _id = null )
8586 {
86- if ($ index ){
87+ if ($ index ) {
8788 $ params = [
88- 'index ' => $ index
89+ 'index ' => $ index,
8990 ];
9091 }
9192
@@ -108,7 +109,7 @@ public static function buildParams($index, $wheres, $options = [], $columns = []
108109 }
109110 }
110111 }
111- if (self ::$ filter ){
112+ if (self ::$ filter ) {
112113 $ params = self ::_parseFilterParameter ($ params , self ::$ filter );
113114 }
114115
@@ -173,7 +174,7 @@ private static function _ninQueryString($key, $values): string
173174 private static function _parseParams ($ key , $ value ): string
174175 {
175176
176- if ($ key == 'and ' || $ key == 'or ' ) {
177+ if ($ key === 'and ' || $ key = == 'or ' ) {
177178 return self ::{'_ ' .$ key .'QueryString ' }($ value );
178179 }
179180 if (is_array ($ value )) {
@@ -301,8 +302,8 @@ private static function _buildOptions($options): array
301302 $ return ['body ' ]['min_score ' ] = $ value ;
302303 break ;
303304 case 'filters ' :
304- foreach ($ value as $ filterType => $ filerValues ){
305- self ::_parseFilter ($ filterType ,$ filerValues );
305+ foreach ($ value as $ filterType => $ filerValues ) {
306+ self ::_parseFilter ($ filterType , $ filerValues );
306307 }
307308 break ;
308309 case 'multiple ' :
@@ -318,22 +319,22 @@ private static function _buildOptions($options): array
318319 return $ return ;
319320 }
320321
321- public static function _parseFilter ($ filterType ,$ filterPayload )
322+ public static function _parseFilter ($ filterType , $ filterPayload )
322323 {
323- switch ($ filterType ){
324+ switch ($ filterType ) {
324325 case 'filterGeoBox ' :
325326 self ::$ filter ['filter ' ]['geo_bounding_box ' ][$ filterPayload ['field ' ]] = [
326- 'top_left ' => $ filterPayload ['topLeft ' ],
327+ 'top_left ' => $ filterPayload ['topLeft ' ],
327328 'bottom_right ' => $ filterPayload ['bottomRight ' ],
328329 ];
329330 break ;
330331 case 'filterGeoPoint ' :
331332 self ::$ filter ['filter ' ]['geo_distance ' ] = [
332- 'distance ' => $ filterPayload ['distance ' ],
333+ 'distance ' => $ filterPayload ['distance ' ],
333334 $ filterPayload ['field ' ] => [
334335 'lat ' => $ filterPayload ['geoPoint ' ][0 ],
335336 'lon ' => $ filterPayload ['geoPoint ' ][1 ],
336- ]
337+ ],
337338
338339 ];
339340 break ;
@@ -354,35 +355,36 @@ private static function _parseSortOrder($value): array
354355 return $ sort ->toArray ();
355356 }
356357
357- public static function _parseFilterParameter ($ params ,$ filer )
358+ public static function _parseFilterParameter ($ params , $ filer )
358359 {
359360 $ body = $ params ['body ' ];
360- if (!empty ($ body ['query ' ]['match_all ' ])){
361+ if (!empty ($ body ['query ' ]['match_all ' ])) {
361362 $ filteredBody = [
362363 'query ' => [
363364 'bool ' => [
364- 'must ' => [
365+ 'must ' => [
365366 'match_all ' => $ body ['query ' ]['match_all ' ],
366367 ],
367- 'filter ' => $ filer ['filter ' ]
368- ]
369- ]
368+ 'filter ' => $ filer ['filter ' ],
369+ ],
370+ ],
370371 ];
371372 $ params ['body ' ] = $ filteredBody ;
372373 }
373- if (!empty ($ body ['query ' ]['query_string ' ])){
374+ if (!empty ($ body ['query ' ]['query_string ' ])) {
374375 $ filteredBody = [
375376 'query ' => [
376377 'bool ' => [
377- 'must ' => [
378+ 'must ' => [
378379 'query_string ' => $ body ['query ' ]['query_string ' ],
379380 ],
380- 'filter ' => $ filer ['filter ' ]
381- ]
382- ]
381+ 'filter ' => $ filer ['filter ' ],
382+ ],
383+ ],
383384 ];
384385 $ params ['body ' ] = $ filteredBody ;
385386 }
387+
386388 return $ params ;
387389 }
388390}
0 commit comments