Example #1
0
    $keyArray = array(array('section', $searchSectionID), array('section_identifier', $section->attribute('identifier')));
    $res->setKeys($keyArray);
}
$viewParameters = array('offset' => $Offset);
$searchData = false;
$tpl->setVariable("search_data", $searchData);
$tpl->setVariable("search_section_id", $searchSectionID);
$tpl->setVariable("search_subtree_array", $subTreeArray);
$tpl->setVariable('search_timestamp', $searchTimestamp);
$tpl->setVariable("search_text", $searchText);
$tpl->setVariable('search_page_limit', $searchPageLimit);
$tpl->setVariable("view_parameters", $viewParameters);
$tpl->setVariable('use_template_search', !$useSearchCode);
if ($http->hasVariable('Mode') && $http->variable('Mode') == 'browse') {
    if (!isset($searchResult)) {
        $searchResult = eZSearch::search($searchText, array("SearchType" => $searchType, "SearchSectionID" => $searchSectionID, "SearchSubTreeArray" => $subTreeArray, 'SearchTimestamp' => $searchTimestamp, "SearchLimit" => $pageLimit, "SearchOffset" => $Offset));
    }
    $sys = eZSys::instance();
    $searchResult['RequestedURI'] = "content/search";
    //    $searchResult['RequestedURISuffix'] = $sys->serverVariable( "QUERY_STRING" );
    $searchResult['RequestedURISuffix'] = 'SearchText=' . urlencode($searchText) . ($searchTimestamp > 0 ? '&SearchTimestamp=' . $searchTimestamp : '') . '&BrowsePageLimit=' . $pageLimit . '&Mode=browse';
    return $Module->run('browse', array(), array("NodeList" => $searchResult, "Offset" => $Offset, "NodeID" => isset($subTreeArray[0]) && $subTreeArray[0] != 1 ? $subTreeArray[0] : null));
}
// --- Compatibility code start ---
if ($useSearchCode) {
    $tpl->setVariable("offset", $Offset);
    $tpl->setVariable("page_limit", $pageLimit);
    $tpl->setVariable("search_text_enc", urlencode($searchText));
    $tpl->setVariable("search_result", $searchResult["SearchResult"]);
    $tpl->setVariable("search_count", $searchResult["SearchCount"]);
    $tpl->setVariable("stop_word_array", $searchResult["StopWordArray"]);
 public static function fetchContentSearch($searchText, $subTreeArray, $offset, $limit, $searchTimestamp, $publishDate, $sectionID, $classID, $classAttributeID, $ignoreVisibility, $limitation, $sortArray)
 {
     $searchArray = eZSearch::buildSearchArray();
     $parameters = array();
     if ($classID !== false) {
         $parameters['SearchContentClassID'] = $classID;
     }
     if ($classAttributeID !== false) {
         $parameters['SearchContentClassAttributeID'] = $classAttributeID;
     }
     if ($sectionID !== false) {
         $parameters['SearchSectionID'] = $sectionID;
     }
     if ($publishDate !== false) {
         $parameters['SearchDate'] = $publishDate;
     }
     if ($sortArray !== false) {
         $parameters['SortArray'] = $sortArray;
     }
     $parameters['SearchLimit'] = $limit;
     $parameters['SearchOffset'] = $offset;
     $parameters['IgnoreVisibility'] = $ignoreVisibility;
     $parameters['Limitation'] = $limitation;
     if ($subTreeArray !== false) {
         $parameters['SearchSubTreeArray'] = $subTreeArray;
     }
     if ($searchTimestamp) {
         $parameters['SearchTimestamp'] = $searchTimestamp;
     }
     $searchResult = eZSearch::search($searchText, $parameters, $searchArray);
     return array('result' => $searchResult);
 }
    } else {
        $subTreeList = array($http->variable('SubTreeArray'));
    }
    foreach ($subTreeList as $subTreeItem) {
        // as form input is generally a string, is_int cannot be used for checking the value type
        if (is_numeric($subTreeItem) && $subTreeItem > 0) {
            $subTreeArray[] = $subTreeItem;
        }
    }
}
$Module->setTitle("Search for: {$searchText}");
$classArray = eZContentClass::fetchList(eZContentClass::VERSION_STATUS_DEFINED, true, false, array('name' => 'asc'));
$sectionArray = eZSection::fetchList();
$searchArray = eZSearch::buildSearchArray();
if ($useSearchCode) {
    $searchResult = eZSearch::search($searchText, array('SearchSectionID' => $searchSectionID, 'SearchContentClassID' => $searchContentClassID, 'SearchContentClassAttributeID' => $searchContentClassAttributeID, 'SearchSubTreeArray' => $subTreeArray, 'SearchDate' => $searchDate, 'SearchTimestamp' => $searchTimestamp, 'SearchLimit' => $pageLimit, 'SearchOffset' => $Offset), $searchArray);
    if (strlen(trim($searchText)) == 0 && count($searchArray) > 0) {
        $searchText = 'search by additional parameter';
    }
}
$viewParameters = array('offset' => $Offset);
$searchData = false;
$tpl->setVariable("search_data", $searchData);
$tpl->setVariable('search_contentclass_id', $searchContentClassID);
$tpl->setVariable('search_contentclass_attribute_id', $searchContentClassAttributeID);
$tpl->setVariable('search_section_id', $searchSectionID);
$tpl->setVariable('search_date', $searchDate);
$tpl->setVariable('search_timestamp', $searchTimestamp);
$tpl->setVariable('search_sub_tree', $subTreeArray);
$tpl->setVariable('search_text', $searchText);
$tpl->setVariable('search_page_limit', $searchPageLimit);
Example #4
0
 /**
  * Returns search results based on given post params
  *
  * @param mixed $args Only used if post parameter is not set
  *              0 => SearchStr
  *              1 => SearchOffset
  *              2 => SearchLimit (10 by default, max 50)
  * @return array
  */
 public static function search($args)
 {
     $http = eZHTTPTool::instance();
     if ($http->hasPostVariable('SearchStr')) {
         $searchStr = trim($http->postVariable('SearchStr'));
     } else {
         if (isset($args[0])) {
             $searchStr = trim($args[0]);
         }
     }
     if ($http->hasPostVariable('SearchOffset')) {
         $searchOffset = (int) $http->postVariable('SearchOffset');
     } else {
         if (isset($args[1])) {
             $searchOffset = (int) $args[1];
         } else {
             $searchOffset = 0;
         }
     }
     if ($http->hasPostVariable('SearchLimit')) {
         $searchLimit = (int) $http->postVariable('SearchLimit');
     } else {
         if (isset($args[2])) {
             $searchLimit = (int) $args[2];
         } else {
             $searchLimit = 10;
         }
     }
     // Do not allow to search for more then x items at a time
     $ini = eZINI::instance();
     $maximumSearchLimit = (int) $ini->variable('SearchSettings', 'MaximumSearchLimit');
     if ($searchLimit > $maximumSearchLimit) {
         $searchLimit = $maximumSearchLimit;
     }
     // Prepare node encoding parameters
     $encodeParams = array();
     if (self::hasPostValue($http, 'EncodingLoadImages')) {
         $encodeParams['loadImages'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchChildrenCount')) {
         $encodeParams['fetchChildrenCount'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchSection')) {
         $encodeParams['fetchSection'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFormatDate')) {
         $encodeParams['formatDate'] = $http->postVariable('EncodingFormatDate');
     }
     // Prepare search parameters
     $params = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SortArray' => array('published', 0), 'SortBy' => array('published' => 'desc'));
     if (self::hasPostValue($http, 'SearchContentClassAttributeID')) {
         $params['SearchContentClassAttributeID'] = self::makePostArray($http, 'SearchContentClassAttributeID');
     } else {
         if (self::hasPostValue($http, 'SearchContentClassID')) {
             $params['SearchContentClassID'] = self::makePostArray($http, 'SearchContentClassID');
         } else {
             if (self::hasPostValue($http, 'SearchContentClassIdentifier')) {
                 $params['SearchContentClassID'] = eZContentClass::classIDByIdentifier(self::makePostArray($http, 'SearchContentClassIdentifier'));
             }
         }
     }
     if (self::hasPostValue($http, 'SearchSubTreeArray')) {
         $params['SearchSubTreeArray'] = self::makePostArray($http, 'SearchSubTreeArray');
     }
     if (self::hasPostValue($http, 'SearchSectionID')) {
         $params['SearchSectionID'] = self::makePostArray($http, 'SearchSectionID');
     }
     if (self::hasPostValue($http, 'SearchDate')) {
         $params['SearchDate'] = (int) $http->postVariable('SearchDate');
     } else {
         if (self::hasPostValue($http, 'SearchTimestamp')) {
             $params['SearchTimestamp'] = self::makePostArray($http, 'SearchTimestamp');
             if (!isset($params['SearchTimestamp'][1])) {
                 $params['SearchTimestamp'] = $params['SearchTimestamp'][0];
             }
         }
     }
     if (self::hasPostValue($http, 'EnableSpellCheck') || self::hasPostValue($http, 'enable-spellcheck', '0')) {
         $params['SpellCheck'] = array(true);
     }
     if (self::hasPostValue($http, 'GetFacets') || self::hasPostValue($http, 'show-facets', '0')) {
         $params['facet'] = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array());
     }
     $result = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SearchResultCount' => 0, 'SearchCount' => 0, 'SearchResult' => array(), 'SearchString' => $searchStr, 'SearchExtras' => array());
     // Possibility to keep track of callback reference for use in js callback function
     if ($http->hasPostVariable('CallbackID')) {
         $result['CallbackID'] = $http->postVariable('CallbackID');
     }
     // Only search if there is something to search for
     if ($searchStr) {
         $searchList = eZSearch::search($searchStr, $params);
         $result['SearchResultCount'] = $searchList['SearchResult'] !== false ? count($searchList['SearchResult']) : 0;
         $result['SearchCount'] = (int) $searchList['SearchCount'];
         $result['SearchResult'] = ezjscAjaxContent::nodeEncode($searchList['SearchResult'], $encodeParams, false);
         // ezfind stuff
         if (isset($searchList['SearchExtras']) && $searchList['SearchExtras'] instanceof ezfSearchResultInfo) {
             if (isset($params['SpellCheck'])) {
                 $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck');
             }
             if (isset($params['facet'])) {
                 $facetInfo = array();
                 $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields');
                 $baseSearchUrl = "/content/search/";
                 eZURI::transformURI($baseSearchUrl, false, 'full');
                 foreach ($params['facet'] as $key => $defaultFacet) {
                     $facetData = $retrievedFacets[$key];
                     $facetInfo[$key] = array('name' => $defaultFacet['name'], 'list' => array());
                     if ($facetData !== null) {
                         foreach ($facetData['nameList'] as $key2 => $facetName) {
                             if ($key2 != '') {
                                 $tmp = array('value' => $facetName);
                                 $tmp['url'] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName;
                                 $tmp['count'] = $facetData['countList'][$key2];
                                 $facetInfo[$key]['list'][] = $tmp;
                             }
                         }
                     }
                 }
                 $result['SearchExtras']['facets'] = $facetInfo;
             }
         }
         //$searchList['SearchExtras'] instanceof ezfSearchResultInfo
     }
     // $searchStr
     return $result;
 }