コード例 #1
0
ファイル: search.php プロジェクト: mrdeadmouse/u136006
 function StemIndex($arLID, $ID, $sContent)
 {
     $DB = CDatabase::GetModuleConnection('search');
     static $CACHE_SITE_LANGS = array();
     $ID = intval($ID);
     $arLang = array();
     if (!is_array($arLID)) {
         $arLID = array();
     }
     foreach ($arLID as $site => $url) {
         if (!array_key_exists($site, $CACHE_SITE_LANGS)) {
             $db_site_tmp = CSite::GetByID($site);
             if ($ar_site_tmp = $db_site_tmp->Fetch()) {
                 $CACHE_SITE_LANGS[$site] = array("LANGUAGE_ID" => $ar_site_tmp["LANGUAGE_ID"], "CHARSET" => $ar_site_tmp["CHARSET"], "SERVER_NAME" => $ar_site_tmp["SERVER_NAME"]);
             } else {
                 $CACHE_SITE_LANGS[$site] = false;
             }
         }
         if (is_array($CACHE_SITE_LANGS[$site])) {
             $arLang[$CACHE_SITE_LANGS[$site]["LANGUAGE_ID"]] = true;
         }
     }
     foreach ($arLang as $lang => $value) {
         $sql_lang = $DB->ForSql($lang);
         $arDoc = stemming($sContent, $lang);
         $docLength = array_sum($arDoc);
         if (BX_SEARCH_VERSION > 1) {
             $arPos = stemming($sContent, $lang, false, true);
             CSearch::RegisterStem($arDoc);
         }
         if ($docLength > 0) {
             $doc = "";
             $logDocLength = log($docLength < 20 ? 20 : $docLength);
             $strSqlPrefix = "\n\t\t\t\t\t\tinsert ignore into b_search_content_stem\n\t\t\t\t\t\t(SEARCH_CONTENT_ID, LANGUAGE_ID, STEM, TF" . (BX_SEARCH_VERSION > 1 ? ",PS" : "") . ")\n\t\t\t\t\t\tvalues\n\t\t\t\t";
             $maxValuesLen = 2048;
             $strSqlValues = "";
             if (BX_SEARCH_VERSION > 1) {
                 foreach ($arDoc as $word => $count) {
                     $stem_id = CSearch::RegisterStem($word);
                     //This is almost impossible, but happens
                     if ($stem_id > 0) {
                         $strSqlValues .= ",\n(" . $ID . ", '" . $sql_lang . "'" . ", " . CSearch::RegisterStem($word) . ", " . number_format(log($count + 1) / $logDocLength, 4, ".", "") . ", " . number_format($arPos[$word] / $count, 4, ".", "") . ")";
                     }
                     if (strlen($strSqlValues) > $maxValuesLen) {
                         $DB->Query($strSqlPrefix . substr($strSqlValues, 2), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         $strSqlValues = "";
                     }
                 }
             } else {
                 foreach ($arDoc as $word => $count) {
                     $strSqlValues .= ",\n(" . $ID . ", '" . $sql_lang . "'" . ", '" . $DB->ForSQL($word) . "'" . ", " . number_format(log($count + 1) / $logDocLength, 4, ".", "") . ")";
                     if (strlen($strSqlValues) > $maxValuesLen) {
                         $DB->Query($strSqlPrefix . substr($strSqlValues, 2), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         $strSqlValues = "";
                     }
                 }
             }
             if (strlen($strSqlValues) > 0) {
                 $DB->Query($strSqlPrefix . substr($strSqlValues, 2), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 $strSqlValues = "";
             }
         }
     }
 }