75 $isUtf = defined(
'BX_UTF') && BX_UTF ===
true;
79 [$content, $query] = \Bitrix\Main\Text\Encoding::convertEncoding(
80 [$content, $query], SITE_CHARSET,
'UTF-8'
84 $phrases = explode(
' ', $query);
85 \trimArr($phrases,
true);
89 foreach ($phrases as $phrase)
91 $phrasePos = mb_strpos(mb_strtolower($content), mb_strtolower($phrase));
92 if ($phrasePos ===
false)
96 $newContent .= (($phrasePos > $snippetOffset) ?
' ...' :
' ') .
99 ($phrasePos > $snippetOffset) ? $phrasePos - $snippetOffset : 0,
100 $phrasePos + mb_strlen($phrase) + $snippetOffset
107 $newContent = \Bitrix\Main\Text\Encoding::convertEncoding(
108 $newContent,
'UTF-8', SITE_CHARSET
122 $needPreviewPicture =
false;
123 $needPreviewText =
false;
141 if (isset($contextFilter[
'SITE_ID']))
143 $filter[
'SITE_ID'] = $contextFilter[
'SITE_ID'];
145 if (isset($contextFilter[
'LANDING_ACTIVE']))
147 $filter[
'=ACTIVE'] = $contextFilter[
'LANDING_ACTIVE'];
149 $filter[
'==AREAS.ID'] =
null;
155 if (isset($rawOrder[
'by']) && isset($rawOrder[
'order']))
157 $order[$rawOrder[
'by']] = $rawOrder[
'order'];
158 if (!in_array($rawOrder[
'by'], $select))
160 $select[] = $rawOrder[
'by'];
163 foreach ($select as $i => $code)
165 if ($code ==
'IMAGE')
167 $needPreviewPicture =
true;
170 else if ($code ==
'DESCRIPTION')
172 $needPreviewText =
true;
175 else if ($code ==
'LINK')
193 if ($cache instanceof \CPHPCache)
195 $cache->abortDataCache();
198 if (mb_strlen($query) < 3)
205 if (isset($filter[
'SITE_ID']))
207 $blockFilter[
'LANDING.SITE_ID'] = $filter[
'SITE_ID'];
209 $blocks = Block::search(
212 [
'LID',
'ID',
'SEARCH_CONTENT']
214 $landingBlocksIds = [];
215 foreach ($blocks as $block)
217 $searchContent[$block[
'LID']] = $this->
getSearchSnippet($query, $block[
'SEARCH_CONTENT']);
218 if (!$searchContent[$block[
'LID']])
220 unset($searchContent[$block[
'LID']]);
222 $landingBlocksIds[] = $block[
'LID'];
228 'TITLE' =>
'%' . $query .
'%',
229 '*%SEARCH_CONTENT' => $query,
230 'ID' => $landingBlocksIds ? $landingBlocksIds : [-1]
242 while ($row = $res->fetch())
244 Cache::register($row[
'ID']);
245 $result[$row[
'ID']] = [
246 'TITLE' => \htmlspecialcharsbx($row[
'TITLE'])
253 $needPreviewPicture ||
263 foreach ($result as $id => &$item)
266 $needPreviewPicture &&
267 isset($metaData[$id][
'IMAGE'])
271 'src' => $metaData[$id][
'IMAGE'],
272 'alt' => $item[
'TITLE'] ??
''
275 if ($needPreviewText)
277 if (isset($searchContent[$id]))
279 $item[
'DESCRIPTION'] = \htmlspecialcharsbx($searchContent[$id]);
281 else if (isset($metaData[$id][
'DESCRIPTION']))
283 $item[
'DESCRIPTION'] = \htmlspecialcharsbx($metaData[$id][
'DESCRIPTION']);
288 $item[
'LINK'] =
'#landing' . $id;
298 return array_values($result);