7 private $errorText =
'';
8 private $errorNumber = 0;
21 if (!preg_match(
'/^[a-zA-Z0-9_-]+$/',
$indexName))
29 throw new \Bitrix\Main\Db\ConnectionException(
'OpenSearch connect error',
GetMessage(
'SEARCH_OPENSEARCH_CONN_ERROR_INDEX_NAME'));
36 'disableSslVerification' =>
true,
41 if ($server->getStatus() !== 200 || !is_array(json_decode($strJson,
true)))
50 throw new \Bitrix\Main\Db\ConnectionException(
'OpenSearch connect error',
GetMessage(
'SEARCH_OPENSEARCH_CONN_ERROR', [
'#ERRSTR#' =>
$error]));
60 if (!$this->siteAnalyzerMap)
65 $analyzer = COption::GetOptionString(
'search',
'opensearch_analyzer_' .
$site[
'ID']);
68 $analyzer = array_search(
$site[
'LANGUAGE_ID'], static::getLanguageAnalyzers()) ?:
'english';
70 $this->siteAnalyzerMap[
$site[
'ID']] = $analyzer;
76 foreach ($this->siteAnalyzerMap as
$siteId => $analyzer)
87 $this->connectionIndex = $connectionIndex;
115 'indonesian' =>
'ms',
119 'lithuanian' =>
'lt',
137 $result = $this->
query(
'GET',
'/_index_template/' . $templateName);
138 if (!
$result && $this->errorNumber !== 404)
144 isset(
$result[
'index_templates'][0][
'index_template'][
'version'])
148 $analyzerMatch =
true;
152 isset(
$result[
'index_templates'][0][
'index_template'][
'template'][
'mappings'][
'properties'][
'body'][
'analyzer'])
153 &&
$result[
'index_templates'][0][
'index_template'][
'template'][
'mappings'][
'properties'][
'body'][
'analyzer'] === $analyzer
158 $analyzerMatch = !isset(
$result[
'index_templates'][0][
'index_template'][
'template'][
'mappings'][
'properties'][
'body'][
'analyzer']);
161 $updateNeeded = !$versionMatch || !$analyzerMatch;
165 $result = $this->
query(
'DELETE',
'/_index_template/' . $templateName);
168 if ($this->errorNumber === 404 || $updateNeeded)
178 'format' =>
'date_time_no_millis',
180 'date_change_ts' => [
212 'format' =>
'date_time_no_millis',
219 'format' =>
'date_time_no_millis',
240 $template[
'mappings'][
'properties'][
'body'][
'analyzer'] = $analyzer;
243 $result = $this->
query(
'PUT',
'/_index_template/' . $templateName, [
244 'index_patterns' => [
254 'MESSAGE' =>
GetMessage(
"SEARCH_OPENSEARCH_REINDEX", [
'#LINK#' =>
'/bitrix/admin/search_reindex.php?lang=' . LANGUAGE_ID]),
255 'TAG' =>
'SEARCH_REINDEX',
256 'MODULE_ID' =>
'SEARCH',
273 if (isset(static::$siteIdChecked[
$siteId]))
277 static::$siteIdChecked[
$siteId] =
true;
279 $cacheId =
'opensearch-template-' .
$siteId;
280 if (
$CACHE_MANAGER->Read(CACHED_opensearch_template, $cacheId,
'opensearch'))
285 if (isset($this->siteAnalyzerMap[
$siteId]))
295 $this->
query(
'DELETE',
'/' . $this->indexName .
'-*?expand_wildcards=all');
300 foreach ($this->siteAnalyzerMap as
$siteId => $_)
302 $this->
query(
'DELETE',
'/' . $this->indexName .
'-' .
$siteId .
'/_doc/' . intval(
$ID));
308 $DB = CDatabase::GetModuleConnection(
'search');
310 if (array_key_exists(
'~DATE_CHANGE',
$arFields))
322 $arFields[
'DATE_CHANGE'] =
$DB->FormatDate(
$arFields[
'DATE_CHANGE'],
'DD.MM.YYYY HH:MI:SS', CLang::GetDateFormat());
335 foreach ($this->siteAnalyzerMap as
$siteId => $_)
341 'date_change' => $DATE_CHANGE ? date(
'c', $DATE_CHANGE) :
null,
342 'date_change_ts' => $DATE_CHANGE ? $DATE_CHANGE - CTimeZone::GetOffset() : 0,
345 'custom_rank' => intval(
$arFields[
'CUSTOM_RANK']),
350 'date_from' => $DATE_FROM ? date(
'c', $DATE_FROM) :
null,
351 'date_from_ts' => $DATE_FROM ? $DATE_FROM - CTimeZone::GetOffset() : 0,
352 'date_to' => $DATE_TO ? date(
'c', $DATE_TO) :
null,
353 'date_to_ts' => $DATE_TO ? $DATE_TO - CTimeZone::GetOffset() : 0,
362 throw new \Bitrix\Main\Db\SqlQueryException(
'OpenSearch index error', $this->
getError(),
'');
374 $DB = CDatabase::GetModuleConnection(
'search');
378 $bReplace = array_key_exists(
'TITLE',
$arFields)
380 || array_key_exists(
'MODULE_ID',
$arFields)
381 || array_key_exists(
'ITEM_ID',
$arFields)
386 if (array_key_exists(
'~DATE_CHANGE',
$arFields))
398 $arFields[
'DATE_CHANGE'] =
$DB->FormatDate(
$arFields[
'DATE_CHANGE'],
'DD.MM.YYYY HH:MI:SS', CLang::GetDateFormat());
401 if (array_key_exists(
'DATE_CHANGE',
$arFields))
404 $arUpdate[
'date_change'] = $DATE_CHANGE > 0 ? date(
'c', $DATE_CHANGE - CTimeZone::GetOffset()) :
null;
405 $arUpdate[
'date_change_ts'] = $DATE_CHANGE > 0 ? $DATE_CHANGE : 0;
408 if (array_key_exists(
'DATE_FROM',
$arFields))
411 $arUpdate[
'date_from'] = $DATE_FROM > 0 ? date(
'c', $DATE_FROM - CTimeZone::GetOffset()) :
null;
412 $arUpdate[
'date_from_ts'] = $DATE_FROM > 0 ? $DATE_FROM : 0;
415 if (array_key_exists(
'DATE_TO',
$arFields))
418 $arUpdate[
'date_to'] = $DATE_TO > 0 ? date(
'c', $DATE_TO - CTimeZone::GetOffset()) :
null;
419 $arUpdate[
'date_to_ts'] = $DATE_TO > 0 ? $DATE_TO : 0;
422 if (array_key_exists(
'CUSTOM_RANK',
$arFields))
424 $arUpdate[
'custom_rank'] =
$arFields[
'CUSTOM_RANK'] > 0 ? intval(
$arFields[
'CUSTOM_RANK']) : 0;
432 if (array_key_exists(
'PERMISSIONS',
$arFields))
437 if (array_key_exists(
'PARAMS',
$arFields))
442 if (array_key_exists(
'SITE_ID',
$arFields))
449 $dbSites =
$DB->Query(
'SELECT * from b_search_content_site WHERE SEARCH_CONTENT_ID=' .
$ID);
456 if (!empty($arUpdate) && !$bReplace)
458 foreach ($this->siteAnalyzerMap as
$siteId => $_)
474 $dbItem =
$DB->Query(
'SELECT * FROM b_search_content WHERE ID = ' .
$ID);
475 $searchItem = $dbItem->fetch();
479 $dbTags =
$DB->Query(
'SELECT * from b_search_tags WHERE SEARCH_CONTENT_ID=' .
$ID);
480 while ($tag = $dbTags->fetch())
482 $arTags[] = $tag[
'NAME'];
484 $searchItem[
'TAGS'] = $arTags ? implode(
',', $arTags) :
null;
486 $searchItem[
'PERMISSIONS'] = [];
487 $dbRights =
$DB->Query(
'SELECT * from b_search_content_right WHERE SEARCH_CONTENT_ID=' .
$ID);
488 while (
$right = $dbRights->fetch())
490 $searchItem[
'PERMISSIONS'][] =
$right[
'GROUP_CODE'];
493 $searchItem[
'SITE_ID'] = [];
494 $dbSites =
$DB->Query(
'SELECT * from b_search_content_site WHERE SEARCH_CONTENT_ID=' .
$ID);
497 $searchItem[
'SITE_ID'][
$site[
'SITE_ID']] =
$site[
'URL'];
500 $searchItem[
'PARAMS'] = [];
501 $dbParams =
$DB->Query(
'SELECT * from b_search_content_param WHERE SEARCH_CONTENT_ID=' .
$ID);
502 while ($param = $dbParams->fetch())
504 $searchItem[
'PARAMS'][$param[
'PARAM_NAME']][] = $param[
'PARAM_VALUE'];
512 function tags($arLID, $sContent)
515 if (is_array($arLID))
520 foreach ($arTags as $tag)
527 return array_values(
$tags);
533 if (is_array($arRights))
535 foreach ($arRights as $group_id)
537 if (is_numeric($group_id))
539 $rights[$group_id] =
'G' . intval($group_id);
543 $rights[$group_id] = $group_id;
566 return array_values(
$sites);
601 return $this->errorText;
606 return $this->errorNumber;
611 $DB = CDatabase::GetModuleConnection(
'search');
614 $this->errorText =
'';
615 $this->errorNumber = 0;
620 if (is_array($aParamsEx) && isset($aParamsEx[
'LIMIT']))
622 $limit = intval($aParamsEx[
'LIMIT']);
623 unset($aParamsEx[
'LIMIT']);
627 $limit = intval(COption::GetOptionInt(
'search',
'max_result_size'));
635 if (is_array($aParamsEx) && isset($aParamsEx[
'OFFSET']))
637 $offset = intval($aParamsEx[
'OFFSET']);
638 unset($aParamsEx[
'OFFSET']);
641 if (is_array($aParamsEx) && !empty($aParamsEx))
643 $aParamsEx[
'LOGIC'] =
'OR';
665 $query[
'query'][
'bool'][
'must'][] = [
668 'query' => $strQuery,
677 $query[
'query'][
'bool'][
'filter'] = [
693 $query[
'query'][
'bool'][
'must'][] = $arWhere;
696 if ($strQuery || $this->
tags || $bTagsCloud)
701 $query[
'aggregations'] = [
710 'field' =>
'date_change_ts',
717 $r = $this->
query(
'GET',
'/' . $this->indexName .
'-' . $this->
SITE_ID .
'/_search',
$query);
720 throw new \Bitrix\Main\Db\SqlQueryException(
'OpenSearch select error', $this->
getError(), $sql);
726 && isset($r[
'aggregations'])
727 && is_array($r[
'aggregations'])
728 && isset($r[
'aggregations'][
'tags'])
729 && is_array($r[
'aggregations'][
'tags'])
732 foreach ($r[
'aggregations'][
'tags'][
'buckets'] as $searcBucket)
735 'NAME' => $searcBucket[
'key'],
736 'CNT' => $searcBucket[
'doc_count'],
737 'FULL_DATE_CHANGE' => ConvertTimeStamp($searcBucket[
'max_dc'][
'value'] + CTimeZone::GetOffset(),
'FULL'),
738 'DATE_CHANGE' => ConvertTimeStamp($searcBucket[
'max_dc'][
'value'] + CTimeZone::GetOffset(),
'SHORT'),
752 $query[
'fields'] = [
'id',
'module_id',
'param2'];
754 $r = $this->
query(
'GET',
'/' . $this->indexName .
'-' . $this->
SITE_ID .
'/_search',
$query);
757 throw new \Bitrix\Main\Db\SqlQueryException(
'OpenSearch select error', $this->
getError(), json_encode(
$query));
761 $this->arForumTopics = [];
765 && is_array($r[
'hits'])
766 && isset($r[
'hits'][
'hits'])
767 && is_array($r[
'hits'][
'hits'])
770 foreach ($r[
'hits'][
'hits'] as $searchHit)
772 if ($searchHit[
'fields'][
'module_id'][0] ==
'FORUM')
774 if (array_key_exists($searchHit[
'fields'][
'param2'][0], $this->arForumTopics))
778 $this->arForumTopics[$searchHit[
'fields'][
'param2'][0]] =
true;
781 'ID' => $searchHit[
'fields'][
'id'][0],
790 $this->errorText =
GetMessage(
'SEARCH_ERROR3');
791 $this->errorNumber = 3;
806 'match_phrase_prefix' => [
813 'size' => $nTopCount,
826 $query[
'query'][
'bool'][
'must'][] = $arWhere;
832 $query[
'query'][
'bool'][
'filter'] = [
854 throw new \Bitrix\Main\Db\SqlQueryException(
'OpenSearch query error', $this->
getError(), json_encode(
$query));
862 && is_array($r[
'hits'])
863 && isset($r[
'hits'][
'hits'])
864 && is_array($r[
'hits'][
'hits'])
867 foreach ($r[
'hits'][
'hits'] as $searchHit)
869 $result[] = $searchHit[
'fields'][
'id'][0];
884 $DB = CDatabase::GetModuleConnection(
'search');
887 if (is_array($value))
897 foreach ($value as
$i => $v)
899 $arWhere[
'bool'][$logic][] = [
911 if ($value !==
false)
932 $DB = CDatabase::GetModuleConnection(
'search');
958 $field = mb_strtoupper($field);
963 && $field !==
'PARAMS'
964 && !is_numeric($field)
977 array_push($arWhere[
'bool'][$logic], $cond);
986 array_push($arWhere[
'bool'][$logic], $this->
filterField(
'item_id',
$val,
'must_not'));
991 if (
$val !==
false &&
$val !==
'no')
996 array_push($arWhere[
'bool'][$logic], $cond);
1007 array_push($arWhere[
'bool'][$logic], $this->
filterField(
'module_id',
$val,
'must_not'));
1015 array_push($arWhere[
'bool'][$logic], $cond);
1025 array_push($arWhere[
'bool'][$logic], $this->
filterField(
'param1',
$val,
'must_not'));
1033 array_push($arWhere[
'bool'][$logic], $cond);
1043 array_push($arWhere[
'bool'][$logic], $this->
filterField(
'param2',
$val,
'must_not'));
1047 case '>=DATE_CHANGE':
1051 $arWhere[
'bool'][$logic][] = [
1053 'date_change_ts' => [
1056 'include_lower' =>
true,
1057 'include_upper' =>
true,
1063 case '<=DATE_CHANGE':
1067 $arWhere[
'bool'][$logic][] = [
1069 'date_change_ts' => [
1072 'include_lower' =>
true,
1073 'include_upper' =>
true,
1082 $ts = time() - CTimeZone::GetOffset();
1083 $arWhere[
'bool'][$logic][] = [
1101 'include_lower' =>
true,
1102 'include_upper' =>
true,
1124 'include_lower' =>
true,
1125 'include_upper' =>
true,
1138 $arTags = explode(
',',
$val);
1139 foreach ($arTags as
$i => &$strTag)
1141 $strTag = trim($strTag,
" \n\r\t\"");
1149 $cond = $this->
filterField(
'tag', $arTags,
'must');
1152 array_push($arWhere[
'bool'][$logic], $cond);
1163 'param.' .
$key => [
1171 array_push($arWhere[
'bool'][$logic], [
1182 case 'USE_TF_FILTER':
1185 if (is_numeric($field) && is_array(
$val))
1190 $arWhere[
'bool'][$logic][] = $subFilter;
1201 if (!$arWhere[
'bool'][$logic])
1212 $DB = CDatabase::GetModuleConnection(
'search');
1216 if (!
$USER->IsAdmin())
1218 if (
$USER->GetID() > 0)
1221 $rs =
$DB->Query(
'SELECT GROUP_CODE FROM b_search_user_right WHERE USER_ID = ' .
$USER->GetID());
1222 while (
$ar =
$rs->Fetch())
1239 if (!is_array($aSort))
1241 $aSort = [$aSort =>
'ASC'];
1244 $this->flagsUseRatingSort = 0;
1245 foreach ($aSort as
$key => $ord)
1247 $ord = mb_strtoupper($ord) <>
'ASC' ?
'desc' :
'asc';
1260 $arOrder[mb_strtolower(
$key)] = [
'order' => $ord];
1263 $arOrder[
'_score'] = [
'order' => $ord];
1268 if (
count($arOrder) == 0)
1271 'CUSTOM_RANK' =>
'DESC',
1273 'DATE_CHANGE' =>
'DESC',
1282 $this->errorText =
'';
1283 $this->errorNumber = 0;
1288 'disableSslVerification' =>
true,
1293 $server->setAuthorization($this->user, $this->password);
1298 $server->setHeader(
'Content-Type',
'application/json');
1300 $server->query($verb, $this->connectionString .
$url,
$params ? json_encode(
$params) :
false);
1302 $server->getStatus() === 200
1303 || $server->getStatus() === 201
1306 $result = json_decode($server->getResult(),
true);
1311 if ($server->getStatus())
1313 $this->errorText = $server->getResult();
1314 $this->errorNumber = $server->getStatus();
1318 $errors = $server->getError();
1324 $this->errorText =
$result[
'error'];
1325 $this->errorNumber =
$result[
'status'];
1333 if ($this->errorText)
1335 $result =
'[' . $this->errorNumber .
'] ' . $this->errorText;
1349 private $search =
null;
1353 $this->search = $search;
1360 if (array_key_exists(
'CNT', $r))
1364 elseif (array_key_exists(
'ID', $r))
1373 $DB = CDatabase::GetModuleConnection(
'search');
1374 $ID = intval($r[
'ID']);
1376 if ($this->search->SITE_ID)
1393 ,' .
$DB->DateToCharFunction(
'sc.DATE_CHANGE') .
' as FULL_DATE_CHANGE
1394 ,' .
$DB->DateToCharFunction(
'sc.DATE_CHANGE',
'SHORT') .
' as DATE_CHANGE
1396 ,scsite.URL SITE_URL
1398 from b_search_content sc
1399 INNER JOIN b_search_content_site scsite ON sc.ID=scsite.SEARCH_CONTENT_ID
1400 where ID = ' .
$ID .
"
1401 and scsite.SITE_ID = '" .
$DB->ForSql($this->search->SITE_ID) .
"'
1421 ,' .
$DB->DateToCharFunction(
'sc.DATE_CHANGE') .
' as FULL_DATE_CHANGE
1422 ,' .
$DB->DateToCharFunction(
'sc.DATE_CHANGE',
'SHORT') .
' as DATE_CHANGE
1424 from b_search_content sc
1425 where ID = ' .
$ID .
'
static KillEntities($str)
checkTemplateBySiteId($siteId)
searchTitle($phrase='', $arPhrase=[], $nTopCount=5, $arParams=[], $bNotFilter=false, $order='')
filterField($field, $value, $logic='should')
static getLanguageAnalyzers()
connect($connectionString, $user='', $password='', $indexName='', $ignoreErrors=false, $siteAnalyzerMap='')
checkIndexTemplate($indexName, $siteId, $analyzer, $adminNotify=true)
query($verb, $url, $params=[])
search($arParams, $aSort, $aParamsEx, $bTagsCloud)
static CheckCurrentUserGroups()
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
MakeTimeStamp($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']