66use Erichard \ElasticQueryBuilder \Filter \Filter ;
77use Erichard \ElasticQueryBuilder \QueryBuilder ;
88use Exception ;
9+ use Illuminate \Contracts \Config \Repository ;
10+ use Illuminate \Http \Request ;
911use Illuminate \Pagination \LengthAwarePaginator ;
1012use Lelastico \Indices \AbstractElasticIndex ;
1113use Lelastico \Search \Query \Traits \AddQueries ;
1214use Lelastico \Search \Query \Traits \HasPaginationSettings ;
1315use Lelastico \Search \Query \Traits \LogQuery ;
1416use Lelastico \Search \Query \Traits \ParseResultsFromHits ;
17+ use Psr \Log \LoggerInterface ;
1518
1619abstract class AbstractBuilder
1720{
@@ -20,28 +23,21 @@ abstract class AbstractBuilder
2023 use AddQueries;
2124 use ParseResultsFromHits;
2225
23- /**
24- * @var QueryBuilder
25- */
26- public $ query ;
27-
28- /**
29- * @var array|null
30- */
31- public $ select = null ;
26+ protected Request $ request ;
3227
28+ public QueryBuilder $ query ;
29+ public ?array $ select = null ;
3330 /**
3431 * Custom client (by default is resolved by each index).
35- *
36- * @var Client|null
3732 */
38- public $ client = null ;
33+ public ? Client $ client = null ;
3934
40- /**
41- * AvailabilitySearchBuilder constructor.
42- */
43- public function __construct ()
35+ public function __construct (Request $ request , LoggerInterface $ logger , Repository $ config )
4436 {
37+ $ this ->request = $ request ;
38+ $ this ->logger = $ logger ;
39+ $ this ->config = $ config ;
40+
4541 // Create root filter that will be used as "group"
4642 $ this ->filter = Filter::bool ();
4743
@@ -52,13 +48,13 @@ public function __construct()
5248 abstract protected function createIndex (): AbstractElasticIndex ;
5349
5450 /**
55- * Runs a elastic query and returns laravel 's LengthAwarePaginator.
51+ * Runs a elastic query and returns Laravel 's LengthAwarePaginator.
5652 *
5753 * @return LengthAwarePaginator
5854 *
5955 * @throws Exception
6056 */
61- public function paginate ()
57+ public function paginate (): LengthAwarePaginator
6258 {
6359 // Determine the index
6460 $ index = $ this ->createIndex ();
@@ -110,7 +106,6 @@ public function paginate()
110106 // Build simple array with _source array values (we do not need elastic related data)
111107 $ items = $ this ->getResultsFromHits ($ result ['hits ' ]['hits ' ]);
112108
113- // Return array
114109 return new LengthAwarePaginator (
115110 $ items ,
116111 // Use aggregated total entries calculation or total hits
@@ -119,11 +114,14 @@ public function paginate()
119114 : $ result ['hits ' ]['total ' ]['value ' ],
120115 $ this ->perPage ,
121116 $ this ->currentPage ,
122- ['path ' => request ()->fullUrl ()]
117+ [
118+ 'path ' => $ this ->request ->url (),
119+ 'query ' => $ this ->request ->query ->all (),
120+ ]
123121 );
124122 } catch (Exception $ exception ) {
125- if (config ('lelastico.log_failure ' )) {
126- logger ('Elastic search failed ' , [
123+ if ($ this -> config -> get ('lelastico.log_failure ' )) {
124+ $ this -> logger -> error ('Elastic search failed ' , [
127125 'error ' => $ exception ->getMessage (),
128126 'query ' => $ query ,
129127 ]);
@@ -137,7 +135,7 @@ public function paginate()
137135 *
138136 * @return AbstractBuilder
139137 */
140- public function setSelect (array $ select )
138+ public function setSelect (array $ select ): self
141139 {
142140 $ this ->select = $ select ;
143141
0 commit comments