|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\FullText class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Full text search criterion. |
|
17
|
|
|
* |
|
18
|
|
|
* The string provided in this criterion is matched as a full text query |
|
19
|
|
|
* against all indexed content objects in the storage layer. |
|
20
|
|
|
* |
|
21
|
|
|
* Normalization and querying capabilities might depend on the system |
|
22
|
|
|
* configuration or the used search engine and might differ. To find about |
|
23
|
|
|
* supported querying capabilities you can use |
|
24
|
|
|
* {@link \eZ\Publish\API\Repository\SearchService::supports()} method. |
|
25
|
|
|
* |
|
26
|
|
|
* If supported, advanced full text query has the following semantics: |
|
27
|
|
|
* |
|
28
|
|
|
* - If multiple words are specified an OR query is performed. |
|
29
|
|
|
* - Boolean operators are supported: AND (&&), OR (||), NOT (!). |
|
30
|
|
|
* - Required/prohibit operators are supported: +, -. |
|
31
|
|
|
* - Grouping is supported through parentheses. |
|
32
|
|
|
* - Phrases are supported using double quotes. |
|
33
|
|
|
* - Simple wild cards are supported. If an asterisk (*) is used at the end or |
|
34
|
|
|
* beginning of a word this is translated into a wild card query. Thus "fo*" |
|
35
|
|
|
* would match "foo" and "foobar", for example. |
|
36
|
|
|
* - Advanced language analysis (like stemming, synonym expansion and stop word |
|
37
|
|
|
* removal) might be applied to the words provided in the query. |
|
38
|
|
|
* |
|
39
|
|
|
* If advanced full text query is not supported, basic query format will be |
|
40
|
|
|
* available: |
|
41
|
|
|
* |
|
42
|
|
|
* - If multiple words are specified an AND query is performed. OR queries are |
|
43
|
|
|
* not supported. |
|
44
|
|
|
* - Simple wild cards are supported. If an asterisk (*) is used at the end or |
|
45
|
|
|
* beginning of a word this is translated into a wild card query. Thus "fo*" |
|
46
|
|
|
* would match "foo" and "foobar", for example. |
|
47
|
|
|
* - Simple stop word removal might be applied to the words provided in the |
|
48
|
|
|
* query. |
|
49
|
|
|
*/ |
|
50
|
|
|
class FullText extends Criterion implements CustomFieldInterface |
|
51
|
|
|
{ |
|
52
|
|
|
/** |
|
53
|
|
|
* Fuzziness of the fulltext search. |
|
54
|
|
|
* |
|
55
|
|
|
* May be a value between 0. (fuzzy) and 1. (sharp). |
|
56
|
|
|
* |
|
57
|
|
|
* @var float |
|
58
|
|
|
*/ |
|
59
|
|
|
public $fuzziness = 1.; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Boost for certain fields. |
|
63
|
|
|
* |
|
64
|
|
|
* Array of boosts to apply for certain fields – the array should look like |
|
65
|
|
|
* this: |
|
66
|
|
|
* |
|
67
|
|
|
* <code> |
|
68
|
|
|
* array( |
|
69
|
|
|
* 'title' => 2, |
|
70
|
|
|
* … |
|
71
|
|
|
* ) |
|
72
|
|
|
* </code> |
|
73
|
|
|
* |
|
74
|
|
|
* @var array |
|
75
|
|
|
*/ |
|
76
|
|
|
public $boost = []; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Analyzer configuration. |
|
80
|
|
|
* |
|
81
|
|
|
* @TODO: Define how this could look like |
|
82
|
|
|
* |
|
83
|
|
|
* @var mixed |
|
84
|
|
|
*/ |
|
85
|
|
|
public $analyzers; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Analyzer wildcard handling configuration. |
|
89
|
|
|
* |
|
90
|
|
|
* @TODO: Define how this could look like |
|
91
|
|
|
* |
|
92
|
|
|
* @var mixed |
|
93
|
|
|
*/ |
|
94
|
|
|
public $wildcards; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Custom field definitions to query instead of default field. |
|
98
|
|
|
* |
|
99
|
|
|
* @var array |
|
100
|
|
|
*/ |
|
101
|
|
|
protected $customFields = []; |
|
102
|
|
|
|
|
103
|
|
|
public function __construct($value, array $properties = []) |
|
104
|
|
|
{ |
|
105
|
|
|
parent::__construct(null, Operator::LIKE, $value); |
|
106
|
|
|
|
|
107
|
|
|
// Assign additional properties, ugly but with the existing constructor |
|
108
|
|
|
// API the only sensible way, I guess. |
|
109
|
|
|
foreach ($properties as $name => $value) { |
|
110
|
|
|
if (!isset($this->$name)) { |
|
111
|
|
|
throw new \InvalidArgumentException("Unknown property $name."); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$this->$name = $value; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function getSpecifications() |
|
119
|
|
|
{ |
|
120
|
|
|
return [ |
|
121
|
|
|
new Specifications(Operator::LIKE, Specifications::FORMAT_SINGLE), |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set a custom field to query. |
|
127
|
|
|
* |
|
128
|
|
|
* Set a custom field to query for a defined field in a defined type. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $type |
|
131
|
|
|
* @param string $field |
|
132
|
|
|
* @param string $customField |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setCustomField($type, $field, $customField) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->customFields[$type][$field] = $customField; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Retun custom field. |
|
141
|
|
|
* |
|
142
|
|
|
* If no custom field is set, return null |
|
143
|
|
|
* |
|
144
|
|
|
* @param string $type |
|
145
|
|
|
* @param string $field |
|
146
|
|
|
* |
|
147
|
|
|
* @return mixed |
|
148
|
|
|
*/ |
|
149
|
|
View Code Duplication |
public function getCustomField($type, $field) |
|
150
|
|
|
{ |
|
151
|
|
|
if (!isset($this->customFields[$type]) || |
|
152
|
|
|
!isset($this->customFields[$type][$field])) { |
|
153
|
|
|
return null; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return $this->customFields[$type][$field]; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|