4
4
5
5
use Basemkhirat \Elasticsearch \Classes \Bulk ;
6
6
use Basemkhirat \Elasticsearch \Classes \Search ;
7
- use Basemkhirat \Elasticsearch \Collection ;
7
+ use Elasticsearch \Client ;
8
+ use Elasticsearch \Common \Exceptions \BadMethodCallException ;
8
9
9
10
10
11
/**
@@ -16,13 +17,13 @@ class Query
16
17
17
18
/**
18
19
* Native elasticsearch connection instance
19
- * @var Connection
20
+ * @var Client
20
21
*/
21
22
public $ connection ;
22
23
23
24
/**
24
25
* Ignored HTTP errors
25
- * @var array
26
+ * @var string[]
26
27
*/
27
28
public $ ignores = [];
28
29
@@ -157,14 +158,14 @@ class Query
157
158
158
159
/**
159
160
* Elastic model instance
160
- * @var \Basemkhirat\Elasticsearch\ Model
161
+ * @var Model
161
162
*/
162
163
public $ model ;
163
164
164
165
165
166
/**
166
167
* Query constructor.
167
- * @param $connection
168
+ * @param Client|NULL $connection
168
169
*/
169
170
function __construct ($ connection = NULL )
170
171
{
@@ -196,7 +197,7 @@ public function getIndex()
196
197
/**
197
198
* Set the type name
198
199
* @param $type
199
- * @return $this
200
+ * @return Query $this
200
201
*/
201
202
public function type ($ type )
202
203
{
@@ -256,7 +257,7 @@ public function searchType($type)
256
257
257
258
/**
258
259
* get the query search type
259
- * @return $this
260
+ * @return int
260
261
*/
261
262
public function getSearchType ()
262
263
{
@@ -265,7 +266,7 @@ public function getSearchType()
265
266
266
267
/**
267
268
* Get the query scroll
268
- * @return $this
269
+ * @return string
269
270
*/
270
271
public function getScroll ()
271
272
{
@@ -362,11 +363,7 @@ public function orderBy($field, $direction = "asc")
362
363
protected function isOperator ($ string )
363
364
{
364
365
365
- if (in_array ($ string , $ this ->operators )) {
366
- return true ;
367
- }
368
-
369
- return false ;
366
+ return in_array ($ string , $ this ->operators );
370
367
}
371
368
372
369
/**
@@ -656,6 +653,7 @@ public function distance($name, $value, $distance)
656
653
/**
657
654
* Search the entire document fields
658
655
* @param null $q
656
+ * @param NULL $settings
659
657
* @return $this
660
658
*/
661
659
public function search ($ q = NULL , $ settings = NULL )
@@ -792,22 +790,21 @@ public function clear($scroll_id = NULL)
792
790
793
791
/**
794
792
* Get the collection of results
795
- * @param string $scroll_id
796
- * @return array| Collection
793
+ * @throws \Exception
794
+ * @return Collection
797
795
*/
798
- public function get ($ scroll_id = NULL )
796
+ public function get ()
799
797
{
800
798
801
- $ scroll_id = NULL ;
802
-
803
- $ result = $ this ->getResult ($ scroll_id );
799
+ $ result = $ this ->getResult (NULL );
804
800
805
801
return $ this ->getAll ($ result );
806
802
}
807
803
808
804
/**
809
805
* Get the first object of results
810
806
* @param string $scroll_id
807
+ * @throws \Exception
811
808
* @return object
812
809
*/
813
810
public function first ($ scroll_id = NULL )
@@ -823,6 +820,7 @@ public function first($scroll_id = NULL)
823
820
/**
824
821
* Get query result
825
822
* @param $scroll_id
823
+ * @throws \Exception
826
824
* @return mixed
827
825
*/
828
826
protected function getResult ($ scroll_id )
@@ -846,7 +844,8 @@ protected function getResult($scroll_id)
846
844
/**
847
845
* Get non cached results
848
846
* @param null $scroll_id
849
- * @return mixed
847
+ * @throws \Exception
848
+ * @return array
850
849
*/
851
850
public function response ($ scroll_id = NULL )
852
851
{
@@ -909,7 +908,7 @@ function setModel($model)
909
908
/**
910
909
* Retrieve all records
911
910
* @param array $result
912
- * @return array| Collection
911
+ * @return Collection
913
912
*/
914
913
protected function getAll ($ result = [])
915
914
{
@@ -993,6 +992,7 @@ protected function getFirst($result = [])
993
992
* @param int $per_page
994
993
* @param $page_name
995
994
* @param null $page
995
+ * @throws \Exception
996
996
* @return Pagination
997
997
*/
998
998
public function paginate ($ per_page = 10 , $ page_name = "page " , $ page = null )
@@ -1013,7 +1013,7 @@ public function paginate($per_page = 10, $page_name = "page", $page = null)
1013
1013
* Insert a document
1014
1014
* @param $data
1015
1015
* @param null $_id
1016
- * @return object
1016
+ * @return array
1017
1017
*/
1018
1018
public function insert ($ data , $ _id = NULL )
1019
1019
{
@@ -1039,12 +1039,12 @@ public function insert($data, $_id = NULL)
1039
1039
$ parameters ["id " ] = $ this ->_id ;
1040
1040
}
1041
1041
1042
- return ( object ) $ this ->connection ->index ($ parameters );
1042
+ return $ this ->connection ->index ($ parameters );
1043
1043
}
1044
1044
1045
1045
/**
1046
1046
* Insert a bulk of documents
1047
- * @param $data multidimensional array of [id => data] pairs
1047
+ * @param $data callable|array : multidimensional array of [id => data] pairs
1048
1048
* @return object
1049
1049
*/
1050
1050
public function bulk ($ data )
@@ -1321,7 +1321,6 @@ public function CachePrefix($prefix)
1321
1321
1322
1322
/**
1323
1323
* Get a unique cache key for the complete query.
1324
- *
1325
1324
* @return string
1326
1325
*/
1327
1326
public function getCacheKey ()
@@ -1357,7 +1356,7 @@ public function remember($minutes, $key = null)
1357
1356
/**
1358
1357
* Indicate that the query results should be cached forever.
1359
1358
* @param string $key
1360
- * @return \Illuminate\Database\Query\Builder|static
1359
+ * @return $this
1361
1360
*/
1362
1361
public function rememberForever ($ key = null )
1363
1362
{
@@ -1372,20 +1371,14 @@ public function rememberForever($key = null)
1372
1371
function __call ($ method , $ parameters )
1373
1372
{
1374
1373
1375
- if (method_exists ($ this , $ method )) {
1376
- return $ this ->$ method (...$ parameters );
1377
- } else {
1378
-
1379
- // Check for model scopes
1374
+ $ method = "scope " . ucfirst ($ method );
1380
1375
1381
- $ method = "scope " . ucfirst ($ method );
1382
-
1383
- if (method_exists ($ this ->model , $ method )) {
1384
- $ parameters = array_merge ([$ this ], $ parameters );
1385
- $ this ->model ->$ method (...$ parameters );
1386
- return $ this ;
1387
- }
1376
+ if (method_exists ($ this ->model , $ method )) {
1377
+ $ parameters = array_merge ([$ this ], $ parameters );
1378
+ $ this ->model ->$ method (...$ parameters );
1379
+ return $ this ;
1388
1380
}
1389
1381
1382
+ throw new BadMethodCallException ("Method $ method does not exist. " );
1390
1383
}
1391
1384
}
0 commit comments