13 if (!static::isIndexExists() || !static::CheckModule())
27 $whereInAll =
array();
29 foreach ($words as $word)
31 $whereInAll[] =
"'".$DB->ForSql($word).
"'";
34 $whereIn =
'TS.SEARCH_WORD IN ('.join(
', ', $whereInAll).
')';
36 if (
count($words) > 1)
38 $having =
'SUM(CASE WHEN '.$whereIn.
' THEN 1 ELSE 0 END) = '.
count($words);
42 return array(
'WHERE' => $whereIn,
'HAVING' => $having);
50 if(!self::CheckModule())
return "";
70 $arrQ = explode(
" ", $q);
71 foreach($arrQ as
$k => $t)
81 if(($t ==
"||") || ($t ==
"&&") || ($t ==
")"))
98 elseif(($t ==
'"') || ($t ==
"'"))
111 if(($t ==
"||") || ($t ==
"&&"))
114 if($t ==
"||") $sRes .=
" OR";
115 else $sRes .=
" AND";
134 $inQuoteS =
"%" . str_replace(
"^",
" ", $inQuoteS) .
"%";
135 $sRes .=
"\n ($titleName LIKE '" .
$DB->ForSql($inQuoteS) .
"' OR $messageName LIKE '" .
$DB->ForSql($inQuoteS) .
"')";
139 elseif(($t !=
"'") && ($t !=
'"'))
147 if(($errorno == 0) && (
$n != 0))
152 if(($errorno == 0) && ($quote !=
""))
177 array(
"&" ,
"|" ,
"~" ,
"(" ,
")",
'"',
"'"),
178 array(
" && ",
" || ",
" ! ",
" (",
") ",
' " ',
" ' "),
182 $q = preg_replace(
"/\\s+/u",
" ", $q);
194 $qwe=preg_replace(
"/\\s{0,}\\+ {0,}/",
"&", $qwe);
196 $qwe=preg_replace(
"/\\s{0,}([()|~]) {0,}/",
"\\1", $qwe);
198 $qwe=preg_replace(
"/(\\s{1,}|\\&\\|{1,}|\\|\\&{1,})/", $default_op, $qwe);
201 $qwe=preg_replace(
"/\\|+/",
"|", $qwe);
202 $qwe=preg_replace(
"/\\&+/",
"&", $qwe);
203 $qwe=preg_replace(
"/\\~+/",
"~", $qwe);
204 $qwe=preg_replace(
"/\\|\\&\\|/",
"&", $qwe);
205 $qwe=preg_replace(
"/[|&~]+$/",
"", $qwe);
206 $qwe=preg_replace(
"/^[|&]+/",
"", $qwe);
215 $qwe=preg_replace(
"/([^&~|()]+)~([^&~|()]+)/",
"\\1".$default_op.
"~\\2", $qwe);
216 $qwe=preg_replace(
"/\\)~{1,}/",
")".$default_op.
"~", $qwe);
217 $qwe=preg_replace(
"/~{1,}\\(/", ($default_op==
"|"?
"~|(":
"&~("), $qwe);
218 $qwe=preg_replace(
"/\\)([^&~|()]+)/",
")".$default_op.
"\\1", $qwe);
219 $qwe=preg_replace(
"/([^&~|()]+)\\(/",
"\\1".$default_op.
"(", $qwe);
220 $qwe=preg_replace(
"/\\) *\\(/",
")".$default_op.
"(", $qwe);
223 $qwe=preg_replace(
"/\\|+/",
"|", $qwe);
224 $qwe=preg_replace(
"/\\&+/",
"&", $qwe);
227 $qwe=preg_replace(
"/\\(\\&{1,}/",
"(", $qwe);
228 $qwe=preg_replace(
"/\\&{1,}\\)/",
")", $qwe);
229 $qwe=preg_replace(
"/\\~{1,}\\)/",
")", $qwe);
230 $qwe=preg_replace(
"/\\(\\|{1,}/",
"(", $qwe);
231 $qwe=preg_replace(
"/\\|{1,}\\)/",
")", $qwe);
232 $qwe=preg_replace(
"/\\~{1,}\\&{1,}/",
"&", $qwe);
233 $qwe=preg_replace(
"/\\~{1,}\\|{1,}/",
"|", $qwe);
235 $qwe=preg_replace(
"/\\(\\)/",
"", $qwe);
236 $qwe=preg_replace(
"/^[|&]{1,}/",
"", $qwe);
237 $qwe=preg_replace(
"/[|&~]{1,}\$/",
"", $qwe);
238 $qwe=preg_replace(
"/\\|\\&/",
"&", $qwe);
239 $qwe=preg_replace(
"/\\&\\|/",
"|", $qwe);
242 $qwe=preg_replace(
"/\\|+/",
"|", $qwe);
243 $qwe=preg_replace(
"/\\&+/",
"&", $qwe);
250 if(self::$searchModule ===
null)
252 self::$searchModule = CModule::IncludeModule(
"search");
255 return self::$searchModule;
260 return (COption::GetOptionString(
'support',
'SEARCH_VERSION',
'0') ===
'12.0.3');
271 $arrQ = explode(
"^", $s);
272 foreach($arrQ as
$k => $v)
274 if(substr_count($v,
"%") > 0)
280 $resArr =
stemming($v, LANGUAGE_ID);
281 if(
count($resArr) > 0)
283 foreach($resArr as $k2 => $v2)
291 $res .=
"\n" . $and .
" ($titleName = '" .
$DB->ForSql($v) .
"' OR $messageName = '" .
$DB->ForSql($v) .
"')";
306 $ticketSearch = self::TABLE_NAME;
307 return "\n" . $and .
" EXISTS(SELECT 1 FROM $ticketSearch WHERE MESSAGE_ID = $idName AND SEARCH_WORD $sign '" .
$DB->ForSql(
$key) .
"')";
318 if(!self::CheckModule())
326 if (!is_array($ticket))
328 $result =
$DB->Query(
"SELECT ID, SITE_ID, TITLE FROM b_ticket WHERE ID = ".intval($ticket));
341 $result =
$DB->Query(
"SELECT MESSAGE FROM b_ticket_message WHERE IS_LOG='N' AND TICKET_ID = ".intval($ticket[
'ID']).
" AND LENGTH(MESSAGE) < 10240");
342 while ($row =
$result->Fetch())
349 if ($ticket[
'SITE_ID'] ===
SITE_ID)
351 $langId = LANGUAGE_ID;
355 $result = CSite::GetByID($ticket[
'SITE_ID']);
363 $langId =
$site[
'LANGUAGE_ID'];
367 $indexText = $ticket[
'TITLE'];
371 $indexText .=
' '.$message[
'MESSAGE'].
' ';
378 foreach (array_keys($index) as $phrase)
380 $insertQuery =
"INSERT INTO " . self::TABLE_NAME .
"(TICKET_ID, SEARCH_WORD) VALUES ".
381 "(".intval($ticket[
'ID']).
", '" .
$DB->ForSql($phrase) .
"')";
383 $DB->Query($insertQuery);
389 if(!self::CheckModule())
396 if (is_array($ticket))
398 $ticketId = intval($ticket[
'ID']);
402 $ticketId = intval($ticket);
405 $DB->Query(
"DELETE FROM ".self::TABLE_NAME.
" WHERE TICKET_ID = ".$ticketId);
407 return static::indexTicket($ticket,
$messages);
412 return static::performAllTicketsIndexing($startFromId, $timeLimit,
false);
417 return static::performAllTicketsIndexing($startFromId, $timeLimit,
true);
422 if (!static::CheckModule())
427 $endTime = time() + $timeLimit;
431 $lastId = intval($startFromId);
433 while (time() < $endTime)
440 T.ID, T.SITE_ID, T.TITLE, TM.MESSAGE
445 TM.TICKET_ID = T.ID AND T.ID > " .
$lastId .
" AND TM.IS_LOG='N'
450 while ($row =
$result->Fetch())
452 $tickets[$row[
'ID']] = $row;
454 $endTicketId = $row[
'ID'];
461 COption::SetOptionString(
'support',
'SEARCH_VERSION',
'12.0.3');
471 $result =
$DB->Query(
"SELECT MESSAGE FROM b_ticket_message WHERE TICKET_ID = ".$endTicketId.
" AND IS_LOG='N' AND LENGTH(MESSAGE) < 10240");
472 while ($row =
$result->Fetch())
480 $ticketIds = array_keys($tickets);
481 $removeFromId = min($ticketIds);
482 $removeToId = max($ticketIds);
484 $DB->Query(
"DELETE FROM ".static::TABLE_NAME.
" WHERE TICKET_ID >= ".$removeFromId.
" AND TICKET_ID <= ".$removeToId);
488 foreach ($tickets as $ticket)
490 static::indexTicket($ticket,
$messages[$ticket[
'ID']]);
504 if(!self::CheckModule())
return;
505 $M_ID = intval($M_ID);
506 $ticketSearch = self::TABLE_NAME;
508 $arrSite = $rsSite->Fetch();
509 $langID = $arrSite[
"LANGUAGE_ID"];
511 $DB->Query(
"DELETE FROM $ticketSearch WHERE MESSAGE_ID = $M_ID");
515 $strSql =
"INSERT INTO " . $ticketSearch .
"(MESSAGE_ID, SEARCH_WORD) VALUES ($M_ID, '" .
$DB->ForSql(
$key) .
"')";
527 $firstID = intval($firstID);
529 $endTime = time() + $periodS;
537 INNER JOIN b_ticket_message TM
538 ON T.ID = TM.TICKET_ID
541 AND LENGTH(TM.MESSAGE) < 10240
545 while($cs =
$res->Fetch())
547 if(time() > $endTime)
return $lastID;
549 $lastID = intval($cs[
"ID"]);
static DeleteByTag($tagId)
static indexTicket($ticket, $messages=null)
static StrInEXISTS($and, $idName, $sign, $key)
GetFilterQuery($q, $idName, $titleName, $messageName, &$error)
static reindexAllTickets($startFromId=0, $timeLimit=10)
static WriteWordsInTable($M_ID, $SITE_ID, $s)
static reindexTicket($ticket, $messages=null)
static indexAllTickets($startFromId=0, $timeLimit=10)
static performAllTicketsIndexing($startFromId=0, $timeLimit=10, $removeOldIndex=false)
static GetSQLfilter($s, $idName, $titleName, $messageName)
PrepareQuery($q, $idName, $titleName, $messageName, &$error)
static ReindexMessages($firstID, $periodS=8)
ParseStr($qwe, $default_op="&")
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
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."%"
stemming($sText, $sLang='ru', $bIgnoreStopWords=false, $bReturnPositions=false)