Ejemplo n.º 1
0
 } elseif ($_REQUEST["order"] == "topic") {
     $arResult["order"]["active"] = "topic";
     $aSort = array("PARAM2" => "DESC", "DATE_CHANGE" => "ASC");
 }
 $arFilter1 = array("MODULE_ID" => "forum", "SITE_ID" => SITE_ID, "QUERY" => $q, "TAGS" => $_REQUEST["tags"] ? $_REQUEST["tags"] : "");
 if (intVal($_REQUEST["DATE_CHANGE"]) > 0) {
     $arFilter1["DATE_CHANGE"] = Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANGUAGE_ID)), time() - intVal($_REQUEST["DATE_CHANGE"]) * 24 * 3600 + CTimeZone::GetOffset());
 }
 $arFilter2 = array();
 if (!empty($arParams["FID_RANGE"]) || !empty($arParams["FID"])) {
     $arFilter2["PARAM1"] = empty($arParams["FID_RANGE"]) ? array() : array_keys($arResult["FORUMS"]);
     $arFilter2["PARAM1"] = empty($arParams["FID"]) ? $arFilter2["PARAM1"] : $arParams["FID"];
 }
 $obSearch = new CSearch();
 //When restart option is set we will ignore error on query with only stop words
 $obSearch->SetOptions(array("ERROR_ON_EMPTY_STEM" => $arParams["RESTART"] != "Y", "NO_WORD_LOGIC" => $arParams["NO_WORD_LOGIC"] == "Y"));
 $obSearch->Search($arFilter1, $aSort, array($arFilter2));
 if ($obSearch->errorno != 0) {
     $arResult["ERROR_MESSAGE"] = $obSearch->error;
 } else {
     $obSearch->NavStart($arParams["TOPICS_PER_PAGE"], false);
     $obSearch->nPageWindow = $arParams["PAGE_NAVIGATION_WINDOW"];
     $arResult["NAV_RESULT"] = $obSearch;
     $arResult["NAV_STRING"] = $obSearch->GetPageNavStringEx($navComponentObject, GetMessage("FL_TOPIC_LIST"), $arParams["PAGE_NAVIGATION_TEMPLATE"]);
     $arResult["EMPTY"] = "Y";
     $topics = array();
     if ($res = $obSearch->GetNext()) {
         $arResult["order"]["~relevance"] = $APPLICATION->GetCurPageParam("q=" . urlencode($q) . (!empty($arParams["FID"]) ? "&FORUM_ID=" . $arParams["FID"] : ""), array("FORUM_ID", "q", "order", "s", BX_AJAX_PARAM_ID));
         $arResult["order"]["~topic"] = $APPLICATION->GetCurPageParam("q=" . urlencode($q) . (!empty($arParams["FID"]) ? "&FORUM_ID=" . $arParams["FID"] : "") . "&order=topic", array("FORUM_ID", "q", "order", "s", BX_AJAX_PARAM_ID));
         $arResult["order"]["~date"] = $APPLICATION->GetCurPageParam("q=" . urlencode($q) . (!empty($arParams["FID"]) ? "&FORUM_ID=" . $arParams["FID"] : "") . "&order=date", array("FORUM_ID", "q", "order", "s", BX_AJAX_PARAM_ID));
         $arResult["order"]["relevance"] = htmlspecialcharsbx($arResult["order"]["~relevance"]);
Ejemplo n.º 2
0
/**
 * $arParams, 
 * $request
 */
function getSearchedElement($arParams, $request)
{
    if (!CModule::IncludeModule("search")) {
        return false;
    }
    $arParams["SHOW_WHEN"] = $arParams["SHOW_WHEN"] == "Y";
    if (!is_array($arParams["arrWHERE"])) {
        $arParams["arrWHERE"] = array();
    }
    $arParams["PAGE_RESULT_COUNT"] = 50;
    if ($arParams["DEFAULT_SORT"] !== "date") {
        $arParams["DEFAULT_SORT"] = "rank";
    }
    if (strlen($arParams["FILTER_NAME"]) <= 0 || !preg_match("/^[A-Za-z_][A-Za-z01-9_]*\$/", $arParams["FILTER_NAME"])) {
        $arFILTERCustom = array();
    } else {
        $arFILTERCustom = $GLOBALS[$arParams["FILTER_NAME"]];
        if (!is_array($arFILTERCustom)) {
            $arFILTERCustom = array();
        }
    }
    $exFILTER = CSearchParameters::ConvertParamsToFilter($arParams, "arrFILTER");
    //options
    if (isset($_REQUEST["q"])) {
        $q = trim($_REQUEST["q"]);
    } else {
        $q = false;
    }
    if ($q !== false) {
        if ($arParams["USE_LANGUAGE_GUESS"] == "N" || isset($_REQUEST["spell"])) {
            $arResult["REQUEST"]["~QUERY"] = $q;
            $arResult["REQUEST"]["QUERY"] = htmlspecialcharsex($q);
        } else {
            $arLang = CSearchLanguage::GuessLanguage($q);
            if (is_array($arLang) && $arLang["from"] != $arLang["to"]) {
                $arResult["REQUEST"]["~ORIGINAL_QUERY"] = $q;
                $arResult["REQUEST"]["ORIGINAL_QUERY"] = htmlspecialcharsex($q);
                $arResult["REQUEST"]["~QUERY"] = CSearchLanguage::ConvertKeyboardLayout($arResult["REQUEST"]["~ORIGINAL_QUERY"], $arLang["from"], $arLang["to"]);
                $arResult["REQUEST"]["QUERY"] = htmlspecialcharsex($arResult["REQUEST"]["~QUERY"]);
            } else {
                $arResult["REQUEST"]["~QUERY"] = $q;
                $arResult["REQUEST"]["QUERY"] = htmlspecialcharsex($q);
            }
        }
    }
    $arResult["URL"] = $APPLICATION->GetCurPage() . "?q=" . urlencode($q) . (isset($_REQUEST["spell"]) ? "&amp;spell=1" : "") . ($tags !== false ? "&amp;tags=" . urlencode($tags) : "");
    if (isset($arResult["REQUEST"]["~ORIGINAL_QUERY"])) {
        $arResult["ORIGINAL_QUERY_URL"] = $APPLICATION->GetCurPage() . "?q=" . urlencode($arResult["REQUEST"]["~ORIGINAL_QUERY"]) . "&amp;spell=1" . "&amp;where=" . urlencode($arResult["REQUEST"]["WHERE"]) . ($arResult["REQUEST"]["HOW"] == "d" ? "&amp;how=d" : "") . ($arResult["REQUEST"]["FROM"] ? '&amp;from=' . urlencode($arResult["REQUEST"]["~FROM"]) : "") . ($arResult["REQUEST"]["TO"] ? '&amp;to=' . urlencode($arResult["REQUEST"]["~TO"]) : "") . ($tags !== false ? "&amp;tags=" . urlencode($tags) : "");
    }
    $templatePage = "";
    $arReturn = false;
    $arFilter = array("SITE_ID" => SITE_ID, "QUERY" => $arResult["REQUEST"]["~QUERY"], "TAGS" => $arResult["REQUEST"]["~TAGS"]);
    $arFilter = array_merge($arFILTERCustom, $arFilter);
    if ($from) {
        $arFilter[">=DATE_CHANGE"] = $from;
    }
    if ($to) {
        $arFilter["<=DATE_CHANGE"] = $to;
    }
    $obSearch = new CSearch();
    //When restart option is set we will ignore error on query with only stop words
    $obSearch->SetOptions(array("ERROR_ON_EMPTY_STEM" => $arParams["RESTART"] != "Y", "NO_WORD_LOGIC" => $arParams["NO_WORD_LOGIC"] == "Y"));
    $obSearch->Search($arFilter, $aSort, $exFILTER);
    $arResult["ERROR_CODE"] = $obSearch->errorno;
    $arResult["ERROR_TEXT"] = $obSearch->error;
    $arResult["SEARCH"] = array();
    if ($obSearch->errorno == 0) {
        $obSearch->NavStart($arParams["PAGE_RESULT_COUNT"], false);
        $ar = $obSearch->GetNext();
        //Search restart
        if (!$ar && $arParams["RESTART"] == "Y" && $obSearch->Query->bStemming) {
            $exFILTER["STEMMING"] = false;
            $obSearch = new CSearch();
            $obSearch->Search($arFilter, $aSort, $exFILTER);
            $arResult["ERROR_CODE"] = $obSearch->errorno;
            $arResult["ERROR_TEXT"] = $obSearch->error;
            if ($obSearch->errorno == 0) {
                $obSearch->NavStart($arParams["PAGE_RESULT_COUNT"], false);
                $ar = $obSearch->GetNext();
            }
        }
        $arReturn = array();
        while ($ar) {
            $arReturn[$ar["ID"]] = $ar["ITEM_ID"];
            $ar["CHAIN_PATH"] = $APPLICATION->GetNavChain($ar["URL"], 0, $folderPath . "/chain_template.php", true, false);
            $ar["URL"] = htmlspecialcharsbx($ar["URL"]);
            $ar["TAGS"] = array();
            if (!empty($ar["~TAGS_FORMATED"])) {
                foreach ($ar["~TAGS_FORMATED"] as $name => $tag) {
                    if ($arParams["TAGS_INHERIT"] == "Y") {
                        $arTags = $arResult["REQUEST"]["~TAGS_ARRAY"];
                        $arTags[$tag] = $tag;
                        $tags = implode(",", $arTags);
                    } else {
                        $tags = $tag;
                    }
                    $ar["TAGS"][] = array("URL" => $APPLICATION->GetCurPageParam("tags=" . urlencode($tags), array("tags")), "TAG_NAME" => htmlspecialcharsex($name));
                }
            }
            $arResult["SEARCH"][] = $ar;
            $ar = $obSearch->GetNext();
        }
        return $arResult;
    }
}