14 $phrase = mb_strtolower(trim($phrase,
" \t\n\r"));
15 if (
$l = mb_strlen($phrase))
19 $p = mb_strrpos($phrase,
' ');
22 $this->_phrase = mb_substr($phrase, 0, 250);
26 $this->_phrase = mb_substr($phrase, 0,
$p);
31 $this->_phrase = $phrase;
36 $this->_phrase =
false;
43 $this->_tags = implode(
', ', $arTags);
52 if (isset($_SESSION[
'SESS_SESSION_ID']))
54 $this->_stat_sess_id = intval($_SESSION[
'SESS_SESSION_ID']);
60 $DB = CDatabase::GetModuleConnection(
'search');
61 $DB->StartUsingMasterOnly();
63 $result_count = intval($result_count);
64 $page_num = intval($page_num);
69 WHERE SESSION_ID = '" .
$DB->ForSQL($this->_session_id) .
"'
70 AND " . ($this->_phrase ===
false ?
'PHRASE IS NULL' :
"PHRASE = '" .
$DB->ForSQL($this->_phrase) .
"'") .
'
71 AND ' . ($this->_tags ===
false ?
'TAGS IS NULL' :
"TAGS = '" .
$DB->ForSQL($this->_tags) .
"'") .
'
76 $this->phrase_id =
$ar[
'ID'];
77 if ($page_num >
$ar[
'PAGES'])
79 $DB->Query(
'UPDATE b_search_phrase SET PAGES = ' . $page_num .
' WHERE ID = ' .
$ar[
'ID']);
84 $this->phrase_id =
$DB->Add(
'b_search_phrase',
86 '~TIMESTAMP_X' =>
$DB->CurrentTimeFunction(),
88 '~RESULT_COUNT' => $result_count,
89 '~PAGES' => $page_num,
90 'SESSION_ID' => $this->_session_id,
91 'PHRASE' => $this->_phrase,
92 'TAGS' => $this->_tags,
93 'STAT_SESS_ID' => $this->_stat_sess_id,
97 $DB->StopUsingMasterOnly();
100 public static function GetList($arOrder =
false,
$arFilter =
false, $arSelect =
false, $bGroup =
false)
102 $DB = CDatabase::GetModuleConnection(
'search');
104 static $arDefSelect = [
118 if (!is_array($arSelect))
122 if (
count($arSelect) < 1)
124 $arSelect = $arDefSelect;
127 if (!is_array($arOrder))
131 if (
count($arOrder) < 1)
139 foreach ($arOrder as $strColumn => $strDirection)
141 $strColumn = mb_strtoupper($strColumn);
142 $strDirection = mb_strtoupper($strDirection) ==
'ASC' ?
'ASC' :
'DESC';
143 if (in_array($strColumn, $arDefSelect))
145 $arSelect[] = $strColumn;
146 if ($strColumn ==
'TIMESTAMP_X')
148 $arQueryOrder[$strColumn] =
'TMP_TS ' . $strDirection;
152 $arQueryOrder[$strColumn] = $strColumn .
' ' . $strDirection;
155 elseif ($strColumn ==
'COUNT' && $bGroup)
157 $arSelect[] = $strColumn;
158 $arQueryOrder[$strColumn] = $strColumn .
' ' . $strDirection;
164 foreach ($arSelect as $strColumn)
166 $strColumn = mb_strtoupper($strColumn);
167 if (in_array($strColumn, $arDefSelect))
169 if ($strColumn ==
'TIMESTAMP_X')
171 $arQuerySelect[
'TMP_TS'] =
'sph.' . $strColumn .
' TMP_TS';
172 $arQuerySelect[$strColumn] =
$DB->DateToCharFunction(
'sph.' . $strColumn,
'FULL') .
' ' . $strColumn;
176 $arQuerySelect[$strColumn] =
'sph.' . $strColumn;
181 $arQueryGroup[$strColumn] =
'sph.' . $strColumn;
184 elseif ($strColumn ==
'COUNT' && $bGroup)
186 $arQuerySelect[$strColumn] =
'count(*) ' . $strColumn;
193 'TABLE_ALIAS' =>
'sph',
194 'FIELD_NAME' =>
'sph.ID',
195 'FIELD_TYPE' =>
'int',
199 'TABLE_ALIAS' =>
'sph',
200 'FIELD_NAME' =>
'sph.PHRASE',
201 'FIELD_TYPE' =>
'string',
205 'TABLE_ALIAS' =>
'sph',
206 'FIELD_NAME' =>
'sph.TAGS',
207 'FIELD_TYPE' =>
'string',
211 'TABLE_ALIAS' =>
'sph',
212 'FIELD_NAME' =>
'sph.TIMESTAMP_X',
213 'FIELD_TYPE' =>
'datetime',
217 'TABLE_ALIAS' =>
'sph',
218 'FIELD_NAME' =>
'sph.SITE_ID',
219 'FIELD_TYPE' =>
'string',
223 'TABLE_ALIAS' =>
'sph',
224 'FIELD_NAME' =>
'sph.URL_TO',
225 'FIELD_TYPE' =>
'string',
229 'TABLE_ALIAS' =>
'sph',
230 'FIELD_NAME' =>
'sph.URL_TO_404',
231 'FIELD_TYPE' =>
'string',
235 'TABLE_ALIAS' =>
'sph',
236 'FIELD_NAME' =>
'sph.STAT_SESS_ID',
237 'FIELD_TYPE' =>
'int',
241 'TABLE_ALIAS' =>
'sph',
242 'FIELD_NAME' =>
'sph.RESULT_COUNT',
243 'FIELD_TYPE' =>
'int',
248 if (
count($arQuerySelect) < 1)
250 $arQuerySelect = [
'ID' =>
'sph.ID'];
255 ' . implode(
', ', $arQuerySelect) .
'
264 if ($strQueryWhere = $obQueryWhere->GetQuery(
$arFilter))
268 ' . $strQueryWhere .
'
272 if ($bGroup &&
count($arQueryGroup) > 0)
276 ' . implode(
', ', $arQueryGroup) .
'
280 if (
count($arQueryOrder) > 0)
284 ' . implode(
', ', $arQueryOrder) .
'
288 return $DB->Query($strSql);
293 $DB = CDatabase::GetModuleConnection(
'search');
294 $cleanup_days = COption::GetOptionInt(
'search',
'stat_phrase_save_days');
295 if ($cleanup_days > 0)
297 $arDate = localtime(time());
298 $date = mktime(0, 0, 0, $arDate[4] + 1, $arDate[3] - $cleanup_days, 1900 + $arDate[5]);
299 $DB->Query(
'DELETE FROM b_search_phrase WHERE TIMESTAMP_X <= ' .
$DB->CharToDateFunction(ConvertTimeStamp($date,
'FULL')));
301 return 'CSearchStatistic::CleanUpAgent();';