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