Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

SearchIndex.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository;
8
9 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
10 use eZ\Publish\Core\Persistence\Database\SelectQuery;
11 use PDO;
12
16 class SearchIndex
17 {
25 protected $dbHandler;
26
32 public function __construct(
33 DatabaseHandler $dbHandler
34 ) {
35 $this->dbHandler = $dbHandler;
36 }
37
45 public function getWords(array $words)
46 {
47 $query = $this->dbHandler->createSelectQuery();
48
49 // use array_map as some DBMS-es do not cast integers to strings by default
50 $query->select('*')
51 ->from('ezsearch_word')
52 ->where($query->expr->in('word', array_map('strval', $words)));
53
54 $stmt = $query->prepare();
55 $stmt->execute();
56
57 return $stmt->fetchAll(PDO::FETCH_ASSOC);
58 }
59
65 public function incrementWordObjectCount(array $wordId)
66 {
67 $this->updateWordObjectCount($wordId, ['object_count' => 'object_count + 1']);
68 }
69
75 public function decrementWordObjectCount(array $wordId)
76 {
77 $this->updateWordObjectCount($wordId, ['object_count' => 'object_count - 1']);
78 }
79
85 public function addWords(array $words)
86 {
87 $query = $this->dbHandler->createInsertQuery();
88 $query->insertInto('ezsearch_word');
89
90 $word = null;
91
92 $query->set(
93 'word',
94 ':word'
95 )->set(
96 'object_count',
97 '1'
98 );
99 $stmt = $query->prepare();
100 foreach ($words as $word) {
101 $stmt->execute(['word' => $word]);
102 }
103 }
104
108 public function purge()
109 {
110 $this->dbHandler->beginTransaction();
111 $query = $this->dbHandler->createDeleteQuery();
112 $tables = [
113 'ezsearch_object_word_link',
114 'ezsearch_search_phrase',
115 'ezsearch_word',
116 ];
117 foreach ($tables as $tbl) {
118 $query->deleteFrom($tbl);
119 $stmt = $query->prepare();
120 $stmt->execute();
121 }
122 $this->dbHandler->commit();
123 }
124
142 public function addObjectWordLink($wordId,
143 $contentId,
144 $frequency,
145 $placement,
146 $nextWordId,
147 $prevWordId,
148 $contentTypeId,
149 $fieldTypeId,
150 $published,
151 $sectionId,
152 $identifier,
153 $integerValue,
154 $languageMask
155 ) {
156 $assoc = [
157 'word_id' => $wordId,
158 'contentobject_id' => $contentId,
159 'frequency' => $frequency,
160 'placement' => $placement,
161 'next_word_id' => $nextWordId,
162 'prev_word_id' => $prevWordId,
163 'contentclass_id' => $contentTypeId,
164 'contentclass_attribute_id' => $fieldTypeId,
165 'published' => $published,
166 'section_id' => $sectionId,
167 'identifier' => $identifier,
168 'integer_value' => $integerValue,
169 'language_mask' => $languageMask,
170 ];
171 $query = $this->dbHandler->createInsertQuery();
172 $query->insertInto('ezsearch_object_word_link');
173 foreach ($assoc as $column => $value) {
174 $query->set($this->dbHandler->quoteColumn($column), $query->bindValue($value));
175 }
176 $stmt = $query->prepare();
177 $stmt->execute();
178 }
179
187 public function getContentObjectWords($contentId)
188 {
189 $query = $this->dbHandler->createSelectQuery();
190
191 $this->setContentObjectWordsSelectQuery($query);
192
193 $stmt = $query->prepare();
194 $stmt->execute(['contentId' => $contentId]);
195
196 $wordIDList = [];
197
198 while (false !== ($row = $stmt->fetch(PDO::FETCH_NUM))) {
199 $wordIDList[] = $row[0];
200 }
201
202 return $wordIDList;
203 }
204
208 public function deleteWordsWithoutObjects()
209 {
210 $query = $this->dbHandler->createDeleteQuery();
211
212 $query->deleteFrom($this->dbHandler->quoteTable('ezsearch_word'))
213 ->where($query->expr->eq($this->dbHandler->quoteColumn('object_count'), ':c'));
214
215 $stmt = $query->prepare();
216 $stmt->execute(['c' => 0]);
217 }
218
224 public function deleteObjectWordsLink($contentId)
225 {
226 $query = $this->dbHandler->createDeleteQuery();
227 $query->deleteFrom($this->dbHandler->quoteTable('ezsearch_object_word_link'))
228 ->where($query->expr->eq($this->dbHandler->quoteColumn('contentobject_id'), ':contentId'));
229
230 $stmt = $query->prepare();
231 $stmt->execute(['contentId' => $contentId]);
232 }
233
239 private function setContentObjectWordsSelectQuery(SelectQuery $query)
240 {
241 $query->select('word_id')
242 ->from($this->dbHandler->quoteTable('ezsearch_object_word_link'))
243 ->where($query->expr->eq($this->dbHandler->quoteColumn('contentobject_id'), ':contentId'));
244 }
245
252 private function updateWordObjectCount(array $wordId, array $columns)
253 {
254 $query = $this->dbHandler->createUpdateQuery();
255 $query->update($this->dbHandler->quoteTable('ezsearch_word'));
256
257 foreach ($columns as $column => $value) {
258 $query->set($this->dbHandler->quoteColumn($column), $value);
259 }
260
261 $query->where($query->expr->in($this->dbHandler->quoteColumn('id'), $wordId));
262
263 $stmt = $query->prepare();
264 $stmt->execute();
265 }
266 }
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex
A service encapsulating database operations on ezsearch* tables.
Definition: SearchIndex.php:17
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\purge
purge()
Remove entire search index.
Definition: SearchIndex.php:108
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\updateWordObjectCount
updateWordObjectCount(array $wordId, array $columns)
Update object count for words (legacy db table: ezsearch_word).
Definition: SearchIndex.php:252
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\incrementWordObjectCount
incrementWordObjectCount(array $wordId)
Increase the object count of the given words by one.
Definition: SearchIndex.php:65
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\__construct
__construct(DatabaseHandler $dbHandler)
SearchIndex constructor.
Definition: SearchIndex.php:32
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\setContentObjectWordsSelectQuery
setContentObjectWordsSelectQuery(SelectQuery $query)
Set query selecting word ids for content object (method was extracted to be reusable).
Definition: SearchIndex.php:239
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\getContentObjectWords
getContentObjectWords($contentId)
Get all words related to the content object (legacy db table: ezsearch_object_word_link).
Definition: SearchIndex.php:187
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\addWords
addWords(array $words)
Insert new words (legacy db table: ezsearch_word).
Definition: SearchIndex.php:85
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\decrementWordObjectCount
decrementWordObjectCount(array $wordId)
Decrease the object count of the given words by one.
Definition: SearchIndex.php:75
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\getWords
getWords(array $words)
Fetch already indexed words from database (legacy db table: ezsearch_word).
Definition: SearchIndex.php:45
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\deleteWordsWithoutObjects
deleteWordsWithoutObjects()
Delete words not related to any content object.
Definition: SearchIndex.php:208
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\deleteObjectWordsLink
deleteObjectWordsLink($contentId)
Delete relation between a word and a content object.
Definition: SearchIndex.php:224
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\$dbHandler
$dbHandler
Definition: SearchIndex.php:25
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex\addObjectWordLink
addObjectWordLink($wordId, $contentId, $frequency, $placement, $nextWordId, $prevWordId, $contentTypeId, $fieldTypeId, $published, $sectionId, $identifier, $integerValue, $languageMask)
Link word with specific content object (legacy db table: ezsearch_object_word_link).
Definition: SearchIndex.php:142
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
eZ\Publish\Core\Persistence\Database\SelectQuery\select
select()
Opens the query and selects which columns you want to return with the query.
eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository
Definition: SearchIndex.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.