1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
linkurlindex.php
См. документацию.
1<?php
2namespace Bitrix\Im\Model;
3
4use Bitrix\Im\V2\Common\IndexTableTrait;
5use Bitrix\Im\V2\Common\MigrationStatusCheckerTrait;
6use Bitrix\Im\V2\Link\Url\UrlItem;
7use Bitrix\Im\V2\Entity\Url\RichData;
8use Bitrix\Main\ORM\Data\DataManager;
9use Bitrix\Main\ORM\Fields\IntegerField;
10use Bitrix\Main\ORM\Fields\Relations\Reference;
11use Bitrix\Main\ORM\Fields\TextField;
12use Bitrix\Main\ORM\Query\Filter\Helper;
13use Bitrix\Main\ORM\Query\Join;
14use Bitrix\Main\Search\Content;
15use Bitrix\Main\UrlPreview\UrlMetadataTable;
16use Bitrix\Main\Web\Uri;
17
42
44{
45 use MigrationStatusCheckerTrait;
46 use IndexTableTrait;
47
48 protected const FORBIDDEN_WORDS = ['www'];
49
50 protected static string $migrationOptionName = 'im_link_url_migration';
51
57 public static function getTableName()
58 {
59 return 'b_im_link_url_index';
60 }
61
67 public static function getMap()
68 {
69 return [
70 'URL_ID' => new IntegerField(
71 'URL_ID',
72 [
73 'primary' => true,
74 ]
75 ),
76 'SEARCH_CONTENT' => new TextField(
77 'SEARCH_CONTENT',
78 [
79 ]
80 ),
81 'URL' => (new Reference(
82 'URL',
83 LinkUrlTable::class,
84 Join::on('this.URL_ID', 'ref.ID')
85 ))->configureJoinType(Join::TYPE_INNER)
86 ];
87 }
88
89 public static function index(int $limit = 500): void
90 {
91 $urlWithoutIndex = LinkUrlTable::query()
92 ->setSelect(['ID', 'URL', 'PREVIEW_URL_ID'])
93 ->where('IS_INDEXED', false)
94 ->setOrder(['ID' => 'ASC'])
95 ->setLimit($limit)
96 ->fetchCollection()
97 ;
98 $urls = new \Bitrix\Im\V2\Link\Url\UrlCollection($urlWithoutIndex);
99 $urls->fillMetadata(false);
100 $inserts = [];
102 foreach ($urls as $url)
103 {
104 if (!self::isMigrationFinished() && $url->getEntity()->getMetadata()['TYPE'] === UrlMetadataTable::TYPE_DYNAMIC)
105 {
106 //Until the end of the migration, we do not get rich data about dynamic links. To do this, put a stub
107 $url->getEntity()->setRichData(new RichData());
108 }
109 $inserts[] = [
110 'URL_ID' => $url->getId(),
111 'SEARCH_CONTENT' => static::generateSearchIndex($url),
112 ];
113 }
114 static::multiplyInsertWithoutDuplicate($inserts);
115 static::updateIndexStatus($urlWithoutIndex->getIdList());
116 }
117
118 protected static function getBaseDataClass(): string
119 {
120 return LinkUrlTable::class;
121 }
122
123 private static function generateSearchIndex(UrlItem $url): string
124 {
125
126 $uri = new Uri($url->getUrl());
127 $splitUrl = Helper::splitWords($uri->getHost());
128 $splitUrl = array_diff($splitUrl, self::FORBIDDEN_WORDS);
129 $index = $splitUrl;
130 if ($url->getEntity()->isRich())
131 {
132 $richData = $url->getEntity()->getRichData();
133 if ($richData !== null)
134 {
135 $splitTitle = Helper::splitWords($richData->getName());
136 $index = array_merge($splitUrl, $splitTitle);
137 }
138 }
139
140 return Content::prepareStringToken(implode(' ', $index));
141 }
142}
Определения uri.php:17
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$url
Определения iframe.php:7