1 | <?php |
||
5 | class SearchQuery |
||
6 | { |
||
7 | const LOGICAL_OPERATOR_AND = 'and'; |
||
8 | const LOGICAL_OPERATOR_OR = 'or'; |
||
9 | |||
10 | protected $query = ''; |
||
11 | |||
12 | /** @var bool */ |
||
13 | protected $useLocationAwareSearch = false; |
||
14 | |||
15 | /** @var int */ |
||
16 | protected $lat; |
||
17 | |||
18 | /** @var int */ |
||
19 | protected $lng; |
||
20 | |||
21 | /** @var int */ |
||
22 | protected $aroundRadius; |
||
23 | |||
24 | /** @var array */ |
||
25 | protected $dateRestrictions = []; |
||
26 | |||
27 | /** @var array */ |
||
28 | protected $numericFilters = []; |
||
29 | |||
30 | /** @var array */ |
||
31 | protected $facets = []; |
||
32 | |||
33 | /** @var int */ |
||
34 | protected $hitsPerPage = 10000; |
||
35 | |||
36 | /** @var int */ |
||
37 | protected $page = 0; |
||
38 | |||
39 | /** |
||
40 | * Set the query to search for. |
||
41 | * |
||
42 | * @param mixed $query |
||
43 | * |
||
44 | * @return SearchQuery |
||
45 | */ |
||
46 | public function searchFor($query) |
||
52 | |||
53 | /** |
||
54 | * Create a location aware search. |
||
55 | * |
||
56 | * @param int $lat |
||
57 | * @param int $lng |
||
58 | * @param int $aroundRadius |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function aroundLocation($lat, $lng, $aroundRadius = 30000) |
||
71 | |||
72 | /** |
||
73 | * Set a date restriction. |
||
74 | * |
||
75 | * @param string $dateFieldName |
||
76 | * @param string $operation |
||
77 | * @param \DateTime $date |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function withDateRestriction($dateFieldName, $operation, \DateTime $date) |
||
87 | |||
88 | /** |
||
89 | * Set a facet. |
||
90 | * |
||
91 | * @param string $name |
||
92 | * @param string $value |
||
93 | * |
||
94 | * @return $this |
||
95 | */ |
||
96 | public function withFacet($name, $value) |
||
102 | |||
103 | /** |
||
104 | * @param int $hitsPerPage |
||
105 | * |
||
106 | * @return SearchQuery |
||
107 | */ |
||
108 | public function setHitsPerPage($hitsPerPage) |
||
114 | |||
115 | /** |
||
116 | * @param int $page |
||
117 | * |
||
118 | * @return SearchQuery |
||
119 | */ |
||
120 | public function setPage($page) |
||
126 | |||
127 | /** |
||
128 | * Set a numeric filter. |
||
129 | * |
||
130 | * @param string $name |
||
131 | * @param string|array $values |
||
132 | * @param string $logicalOperator |
||
133 | * |
||
134 | * @return $this |
||
135 | */ |
||
136 | public function withNumericFilter($name, $values, $logicalOperator = 'and') |
||
156 | |||
157 | /** |
||
158 | * Get the query as an array. |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | public function toArray() |
||
198 | } |
||
199 |