1 | <?php |
||
19 | class Search |
||
20 | { |
||
21 | /** |
||
22 | * @var Index $index |
||
23 | */ |
||
24 | protected $index; |
||
25 | |||
26 | /** |
||
27 | * @var Query $query |
||
28 | */ |
||
29 | protected $query; |
||
30 | |||
31 | /** |
||
32 | * @var string|boolean $path |
||
33 | */ |
||
34 | private $path; |
||
35 | |||
36 | /** |
||
37 | * @var int $limit |
||
38 | */ |
||
39 | private $limit = 25; |
||
40 | |||
41 | /** |
||
42 | * @var int $offset |
||
43 | */ |
||
44 | private $offset = 0; |
||
45 | |||
46 | /** |
||
47 | * @var LuceneBoolean |
||
48 | */ |
||
49 | private static $boolean; |
||
50 | |||
51 | /** |
||
52 | * Search constructor. |
||
53 | * |
||
54 | * @param Index $index |
||
55 | * @param Query $query |
||
56 | */ |
||
57 | 32 | public function __construct(Index $index, Query $query) |
|
58 | { |
||
59 | 32 | $this->index = $index; |
|
60 | 32 | $this->query = $query; |
|
61 | 32 | } |
|
62 | |||
63 | /** |
||
64 | * @param $name |
||
65 | * @param $arguments |
||
66 | * @return $this |
||
67 | * @throws \BadMethodCallException |
||
68 | */ |
||
69 | 2 | public function __call($name, $arguments) |
|
78 | |||
79 | /** |
||
80 | * @param integer $limit |
||
81 | * @return $this |
||
82 | */ |
||
83 | 1 | public function limit($limit) |
|
88 | |||
89 | /** |
||
90 | * @param integer $offset |
||
91 | * @return $this |
||
92 | */ |
||
93 | 1 | public function offset($offset) |
|
98 | |||
99 | /** |
||
100 | * @param bool|string $path |
||
101 | * @return $this |
||
102 | */ |
||
103 | 21 | public function path($path = false) |
|
108 | |||
109 | /** |
||
110 | * @param $string |
||
111 | * @return $this |
||
112 | */ |
||
113 | 1 | public function raw($string) |
|
118 | |||
119 | /** |
||
120 | * Prepare String |
||
121 | * |
||
122 | * We want to keep everything clean and lowercase here. If you really want case sensitive |
||
123 | * pattern matching, fork and code it... |
||
124 | * |
||
125 | * @param $string |
||
126 | * @return string |
||
127 | */ |
||
128 | 6 | private function prepareString($string) |
|
132 | |||
133 | /** |
||
134 | * @param $string |
||
135 | * @param null|string $field |
||
136 | * @param null $offsets |
||
137 | * @return $this |
||
138 | * @return $this |
||
139 | */ |
||
140 | 2 | public function phrase($string, $field = null, $offsets = null) |
|
145 | |||
146 | /** |
||
147 | * @param $string |
||
148 | * @param null|string $field |
||
149 | * @return $this |
||
150 | */ |
||
151 | 1 | public function fuzzy($string, $field = null) |
|
156 | |||
157 | /** |
||
158 | * @param $string |
||
159 | * @param null|string $field |
||
160 | * @return Term |
||
161 | */ |
||
162 | 4 | protected function indexTerm($string, $field = null) |
|
166 | |||
167 | /** |
||
168 | * @param $string |
||
169 | * @param null|string $field |
||
170 | * @return $this |
||
171 | */ |
||
172 | 1 | public function wildcard($string, $field = null) |
|
177 | |||
178 | /** |
||
179 | * Where |
||
180 | * |
||
181 | * A helper method to access phrase or to pass multiple fields. Phrase doesn't "match" exactly and |
||
182 | * allows searching within the text field rather than matching the whole string. |
||
183 | * |
||
184 | * @param boolean|$string |
||
185 | * @param null|string $field |
||
186 | * @return $this|bool |
||
187 | */ |
||
188 | 2 | public function where($string, $field = null) |
|
196 | |||
197 | /** |
||
198 | * Match |
||
199 | * |
||
200 | * Provides an exact pattern match. |
||
201 | * |
||
202 | * @param $string |
||
203 | * @param string $field |
||
204 | * @return $this |
||
205 | */ |
||
206 | 2 | public function match($string, $field = null) |
|
211 | |||
212 | /** |
||
213 | * @param array $terms |
||
214 | * @return $this |
||
215 | */ |
||
216 | 1 | public function multiTerm(array $terms) |
|
227 | |||
228 | /** |
||
229 | * @param string $string |
||
230 | * @param array $array |
||
231 | * @return mixed |
||
232 | */ |
||
233 | 1 | private function mapWhereArray($string, array $array) |
|
242 | |||
243 | /** |
||
244 | * @param string $string |
||
245 | * @param string|null $field |
||
246 | * @return QueryTerm |
||
247 | */ |
||
248 | 3 | public function term($string, $field = null) |
|
252 | |||
253 | /** |
||
254 | * @return mixed |
||
255 | */ |
||
256 | 2 | public function hits() |
|
262 | |||
263 | /** |
||
264 | * Slice |
||
265 | * |
||
266 | * This may look nasty, but there really isn't another way of offsetting results Lucene, and nor would |
||
267 | * you want to really, that's not what it's designed for. It will be quick up to a thousand and after |
||
268 | * that you should be asking the user to "refine their search". |
||
269 | * |
||
270 | * @param mixed $hits |
||
271 | * @return array |
||
272 | */ |
||
273 | 2 | public function slice($hits) |
|
277 | |||
278 | /** |
||
279 | * @param array|QueryHit $array |
||
280 | * @return mixed |
||
281 | */ |
||
282 | 3 | private function mapIds($array) |
|
291 | |||
292 | /** |
||
293 | * @return LuceneBoolean |
||
294 | */ |
||
295 | 1 | public static function getLastQuery() |
|
299 | } |
||
300 |