Repository navigation
Expand file tree
/
Copy pathEngine.php
More file actions
84 lines (71 loc) · 2.07 KB
/
Copy pathEngine.php
File metadata and controls
84 lines (71 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Scout\Engine;
use Hyperf\Collection\Collection as BaseCollection;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Model;
use Hyperf\Scout\Builder;
abstract class Engine
{
/**
* Update the given model in the index.
*/
abstract public function update(Collection $models): void;
/**
* Remove the given model from the index.
*/
abstract public function delete(Collection $models): void;
/**
* Perform the given search on the engine.
*/
abstract public function search(Builder $builder);
/**
* Perform the given search on the engine.
*/
abstract public function paginate(Builder $builder, int $perPage, int $page);
/**
* Pluck and return the primary keys of the given results.
* @param mixed $results
*/
abstract public function mapIds($results): BaseCollection;
/**
* Map the given results to instances of the given model.
* @param mixed $results
*/
abstract public function map(Builder $builder, $results, Model $model): Collection;
/**
* Get the total count from a raw result returned by the engine.
* @param mixed $results
*/
abstract public function getTotalCount($results): int;
/**
* Flush all of the model's records from the engine.
*/
abstract public function flush(Model $model): void;
/**
* Get the results of the query as a Collection of primary keys.
*/
public function keys(Builder $builder): BaseCollection
{
return $this->mapIds($this->search($builder));
}
/**
* Get the results of the given query mapped onto models.
*/
public function get(Builder $builder): Collection
{
return $this->map(
$builder,
$this->search($builder),
$builder->model
);
}
}