1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway; |
4
|
|
|
|
5
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
6
|
|
|
|
7
|
|
|
abstract class CriterionHandler implements Handler |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Check if this criterion handler accepts to handle the given criterion. |
11
|
|
|
* |
12
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
13
|
|
|
* |
14
|
|
|
* @return bool |
15
|
|
|
*/ |
16
|
|
|
abstract public function accept(Criterion $criterion); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Generate query expression for a Criterion this handler accepts. |
20
|
|
|
* |
21
|
|
|
* accept() must be called before calling this method. |
22
|
|
|
* |
23
|
|
|
* @param CriteriaConverter $converter |
24
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
25
|
|
|
*/ |
26
|
|
|
abstract public function handle(CriteriaConverter $converter, Criterion $criterion); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $value |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
* |
33
|
|
|
* @todo if we get passed a string such as 'xxx AND hello', we should probbaly add double quotes around it, as we |
34
|
|
|
* will otherwise most likely be attempting a match for the world 'hello' on any field, not just one |
35
|
|
|
*/ |
36
|
|
|
protected function escapeValue($value) |
37
|
|
|
{ |
38
|
|
|
return str_replace( |
39
|
|
|
array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'), |
40
|
|
|
array('\\\\', '\\+', '\\-', '\\&&', '\\||', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\"', '\\~', '\\*', '\\?', '\\:', '\\/'), |
41
|
|
|
$value |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param int $value timestamp |
47
|
|
|
*/ |
48
|
|
|
protected function formatDate($value) |
49
|
|
|
{ |
50
|
|
|
return strftime('%Y-%m-%dT%H:%M:%SZ', $value); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|