1 | <?php |
||
22 | class DoctrineDatabase extends Gateway |
||
23 | { |
||
24 | /** |
||
25 | * Max acceptable by any DBMS INT value. |
||
26 | * |
||
27 | * Note: 2^31-1 seems to be the most reasonable value that should work in any setup. |
||
28 | */ |
||
29 | const DB_INT_MAX = 2147483647; |
||
30 | |||
31 | /** |
||
32 | * Database handler. |
||
33 | * |
||
34 | * @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler |
||
35 | */ |
||
36 | protected $dbHandler; |
||
37 | |||
38 | /** |
||
39 | * SPI Content Type Handler. |
||
40 | * |
||
41 | * Need this for being able to pick fields that are searchable. |
||
42 | * |
||
43 | * @var \eZ\Publish\SPI\Persistence\Content\Type\Handler |
||
44 | */ |
||
45 | protected $typeHandler; |
||
46 | |||
47 | /** |
||
48 | * Transformation processor. |
||
49 | * |
||
50 | * Need this for being able to transform text to searchable value |
||
51 | * |
||
52 | * @var \eZ\Publish\Core\Persistence\TransformationProcessor |
||
53 | */ |
||
54 | protected $transformationProcessor; |
||
55 | |||
56 | /** |
||
57 | * LegacySearchService. |
||
58 | * |
||
59 | * Need this for queries on ezsearch* tables |
||
60 | * |
||
61 | * @var \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex |
||
62 | */ |
||
63 | protected $searchIndex; |
||
64 | |||
65 | /** |
||
66 | * Construct from handler handler. |
||
67 | * |
||
68 | * @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $dbHandler |
||
69 | * @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $typeHandler |
||
70 | * @param \eZ\Publish\Core\Persistence\TransformationProcessor $transformationProcessor |
||
71 | * @param \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex $searchIndex |
||
72 | */ |
||
73 | public function __construct( |
||
84 | |||
85 | /** |
||
86 | * Index search engine full text data corresponding to content object field values. |
||
87 | * |
||
88 | * Ported from the legacy code |
||
89 | * @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L45 |
||
90 | * |
||
91 | * @param \eZ\Publish\Core\Search\Legacy\Content\FullTextData $fullTextData |
||
92 | */ |
||
93 | public function index(FullTextData $fullTextData) |
||
153 | |||
154 | /** |
||
155 | * Indexes an array of FullTextData objects. |
||
156 | * |
||
157 | * Note: on large amounts of data make sure to iterate with several calls to this function with |
||
158 | * a limited set of FullTextData objects. Amount you have memory for depends on server, size |
||
159 | * of FullTextData objects & PHP version. |
||
160 | * |
||
161 | * @param \eZ\Publish\Core\Search\Legacy\Content\FullTextData[] $fullTextBulkData |
||
162 | */ |
||
163 | public function bulkIndex(array $fullTextBulkData) |
||
169 | |||
170 | /** |
||
171 | * Remove whole content or a specific version from index. |
||
172 | * |
||
173 | * Ported from the legacy code |
||
174 | * @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L386 |
||
175 | * |
||
176 | * @param mixed $contentId |
||
177 | * @param mixed|null $versionId |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | public function remove($contentId, $versionId = null) |
||
199 | |||
200 | /** |
||
201 | * Remove entire search index. |
||
202 | */ |
||
203 | public function purgeIndex() |
||
207 | |||
208 | /** |
||
209 | * Index wordIndex. |
||
210 | * |
||
211 | * Ported from the legacy code |
||
212 | * |
||
213 | * @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L255 |
||
214 | * |
||
215 | * @param \eZ\Publish\Core\Search\Legacy\Content\FullTextData $fullTextData |
||
216 | * @param array $indexArray |
||
217 | * @param array $wordIDArray |
||
218 | * @param int $placement |
||
219 | * |
||
220 | * @return int last placement |
||
221 | */ |
||
222 | private function indexWords(FullTextData $fullTextData, array $indexArray, array $wordIDArray, $placement = 0) |
||
249 | |||
250 | /** |
||
251 | * Build WordIDArray and update ezsearch_word table. |
||
252 | * |
||
253 | * Ported from the legacy code |
||
254 | * |
||
255 | * @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L155 |
||
256 | * |
||
257 | * @param array $indexArrayOnlyWords words for object to add |
||
258 | * |
||
259 | * @return array wordIDArray |
||
260 | */ |
||
261 | private function buildWordIDArray(array $indexArrayOnlyWords) |
||
304 | } |
||
305 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: