1 | <?php |
||
28 | class SearchDecorator implements ConditionDecoratorInterface, |
||
29 | ManganelAwareInterface |
||
30 | { |
||
31 | |||
32 | use ManganelAwareTrait; |
||
33 | |||
34 | const Ns = __NAMESPACE__; |
||
35 | |||
36 | 32 | public function decorate(&$conditions, SearchCriteria $criteria) |
|
37 | { |
||
38 | 32 | $q = $criteria->getSearch(); |
|
39 | |||
40 | 32 | if (empty($q)) |
|
41 | { |
||
42 | 8 | if(!empty($criteria->getConditions())) |
|
43 | { |
||
44 | 2 | return; |
|
45 | } |
||
46 | 7 | if(!empty($criteria->getMoreLike())) |
|
47 | { |
||
48 | return; |
||
49 | } |
||
50 | // Match all documents if query is null |
||
51 | // stdClass is used here to get `{}` in json, as `[]` causes bad |
||
52 | // request exception! |
||
53 | 7 | $conditions[] = [ |
|
54 | 7 | 'match_all' => new stdClass() |
|
55 | ]; |
||
56 | } |
||
57 | else |
||
58 | { |
||
59 | // Use query string matching |
||
60 | 24 | $decorators = (new PluginFactory())->instance($this->manganel->decorators, $criteria, [ |
|
61 | 24 | QueryStringDecoratorInterface::class |
|
62 | ]); |
||
63 | 24 | $queryStringParams = []; |
|
64 | 24 | foreach ($decorators as $decorator) |
|
65 | { |
||
66 | /* @var $decorator QueryStringDecoratorInterface */ |
||
67 | 24 | $decorator->decorate($queryStringParams, $criteria); |
|
68 | } |
||
69 | 24 | $conditions[] = [ |
|
70 | 24 | 'simple_query_string' => $queryStringParams |
|
71 | ]; |
||
72 | } |
||
73 | 31 | } |
|
74 | |||
75 | 31 | public function getKind() |
|
79 | |||
80 | } |
||
81 |