1 | <?php |
||
11 | class TNTSearchEngine extends Engine |
||
12 | { |
||
13 | /** |
||
14 | * @var TNTSearch |
||
15 | */ |
||
16 | protected $tnt; |
||
17 | |||
18 | /** |
||
19 | * @var Builder |
||
20 | */ |
||
21 | protected $builder; |
||
22 | |||
23 | /** |
||
24 | * Create a new engine instance. |
||
25 | * |
||
26 | * @param TNTSearch $tnt |
||
27 | */ |
||
28 | public function __construct(TNTSearch $tnt) |
||
32 | |||
33 | /** |
||
34 | * Update the given model in the index. |
||
35 | * |
||
36 | * @param Collection $models |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | public function update($models) |
||
57 | |||
58 | /** |
||
59 | * Remove the given model from the index. |
||
60 | * |
||
61 | * @param Collection $models |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function delete($models) |
||
75 | |||
76 | /** |
||
77 | * Perform the given search on the engine. |
||
78 | * |
||
79 | * @param Builder $builder |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function search(Builder $builder) |
||
91 | |||
92 | /** |
||
93 | * Perform the given search on the engine. |
||
94 | * |
||
95 | * @param Builder $builder |
||
96 | * @param int $perPage |
||
97 | * @param int $page |
||
98 | * |
||
99 | * @return mixed |
||
100 | */ |
||
101 | public function paginate(Builder $builder, $perPage, $page) |
||
121 | |||
122 | /** |
||
123 | * Perform the given search on the engine. |
||
124 | * |
||
125 | * @param Builder $builder |
||
126 | * |
||
127 | * @return mixed |
||
128 | */ |
||
129 | protected function performSearch(Builder $builder, array $options = []) |
||
130 | { |
||
131 | $index = $builder->index ?: $builder->model->searchableAs(); |
||
132 | $limit = $builder->limit ?: 10000; |
||
133 | $this->tnt->selectIndex("{$index}.index"); |
||
134 | |||
135 | $this->builder = $builder; |
||
136 | $this->tnt->asYouType = $builder->model->asYouType ?: false; |
||
137 | |||
138 | if ($builder->callback) { |
||
139 | return call_user_func( |
||
140 | $builder->callback, |
||
141 | $this->tnt, |
||
142 | $builder->query, |
||
143 | $options |
||
144 | ); |
||
145 | } |
||
146 | if (array_key_exists('searchBoolean', $this->tnt->config) ? $this->tnt->config['searchBoolean'] : false) { |
||
147 | return $this->tnt->searchBoolean($builder->query, $limit); |
||
148 | } else { |
||
149 | return $this->tnt->search($builder->query, $limit); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Get the filter array for the query. |
||
155 | * |
||
156 | * @param Builder $builder |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | protected function filters(Builder $builder) |
||
166 | |||
167 | /** |
||
168 | * Map the given results to instances of the given model. |
||
169 | * |
||
170 | * @param mixed $results |
||
171 | * @param \Illuminate\Database\Eloquent\Model $model |
||
172 | * |
||
173 | * @return Collection |
||
174 | */ |
||
175 | public function map($results, $model) |
||
195 | |||
196 | /** |
||
197 | * Pluck and return the primary keys of the given results. |
||
198 | * |
||
199 | * @param mixed $results |
||
200 | * @return \Illuminate\Support\Collection |
||
201 | */ |
||
202 | public function mapIds($results) |
||
206 | |||
207 | /** |
||
208 | * Get the total count from a raw result returned by the engine. |
||
209 | * |
||
210 | * @param mixed $results |
||
211 | * |
||
212 | * @return int |
||
213 | */ |
||
214 | public function getTotalCount($results) |
||
218 | |||
219 | public function initIndex($model) |
||
229 | } |