本文整理汇总了PHP中eZSolr::search方法的典型用法代码示例。如果您正苦于以下问题:PHP eZSolr::search方法的具体用法?PHP eZSolr::search怎么用?PHP eZSolr::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZSolr
的用法示例。
在下文中一共展示了eZSolr::search方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNodeIDWithSubtreeArray
/**
* Regression test for issue #17576
* Expected : Result from Solr should holds local Node when searching with subtree_array
* @link http://issues.ez.no/17576
* @group issue17576
*/
public function testNodeIDWithSubtreeArray()
{
$expectedNodeID = 0;
foreach ($this->object->nodes as $node) {
if (strpos($node->attribute('path_string'), '/1/43/') === 0) {
$expectedNodeID = $node->attribute('node_id');
}
}
$res = $this->solrSearch->search('foo', array('SearchOffset' => 0, 'SearchLimit' => 1, 'SearchContentClassID' => 'folder', 'SearchSubTreeArray' => array(43), 'AsObjects' => true, 'IgnoreVisibility' => false, 'QueryHandler' => 'ezpublish', 'EnableElevation' => true, 'ForceElevation' => false));
self::assertEquals($expectedNodeID, $res['SearchResult'][0]->attribute('node_id'), 'Result from Solr should holds local Node when searching with subtree_array');
}
示例2: suggest
/**
* Provides suggestion results when adding tags to object
*
* @static
* @param mixed $args
* @return array
*/
public static function suggest($args)
{
$tags = array();
$siteINI = eZINI::instance('site.ini');
if ($siteINI->variable('SearchSettings', 'SearchEngine') == 'ezsolr' && class_exists('eZSolr')) {
$tagsCount = 1;
$filteredTagsArray = array();
$http = eZHTTPTool::instance();
$tagsString = $http->postVariable('tags_string');
$tagsArray = explode('|#', $tagsString);
$subTreeLimit = $http->postVariable('subtree_limit');
$hideRootTag = $http->postVariable('hide_root_tag') == '1' ? true : false;
if (!empty($tagsArray) && strlen(trim($tagsArray[0])) > 0) {
$solrFilter = '"' . trim($tagsArray[0]) . '"';
$filteredTagsArray[] = strtolower(trim($tagsArray[0]));
for ($i = 1; $i < count($tagsArray); $i++) {
if (strlen(trim($tagsArray[$i])) > 0) {
$solrFilter = $solrFilter . ' OR "' . trim($tagsArray[$i]) . '"';
$filteredTagsArray[] = strtolower(trim($tagsArray[$i]));
$tagsCount++;
}
}
$solrFilter = 'ezf_df_tags:(' . $solrFilter . ')';
$solrSearch = new eZSolr();
$params = array('SearchOffset' => 0, 'SearchLimit' => 0, 'Facet' => array(array('field' => 'ezf_df_tags', 'limit' => 5 + $tagsCount, 'mincount', 1)), 'SortBy' => null, 'Filter' => $solrFilter, 'QueryHandler' => 'ezpublish', 'FieldsToReturn' => null);
$searchResult = $solrSearch->search('', $params);
$facetResult = $searchResult['SearchExtras']->attribute('facet_fields');
$facetResult = $facetResult[0]['nameList'];
$tags = array();
foreach ($facetResult as $facetValue) {
if (!in_array(strtolower($facetValue), $filteredTagsArray)) {
$tags[] = trim($facetValue);
}
}
if (!empty($tags)) {
$tags = eZTagsObject::fetchByKeyword(array($tags));
}
}
}
$returnArray = array();
$returnArray['status'] = 'success';
$returnArray['message'] = '';
$returnArray['tags'] = array();
foreach ($tags as $tag) {
if (!$subTreeLimit > 0 || $subTreeLimit > 0 && strpos($tag->attribute('path_string'), '/' . $subTreeLimit . '/') !== false) {
if (!$hideRootTag || $hideRootTag && $tag->attribute('id') != $subTreeLimit) {
$returnArrayChild = array();
$returnArrayChild['tag_parent_id'] = (int) $tag->attribute('parent_id');
$returnArrayChild['tag_parent_name'] = $tag->hasParent() ? $tag->getParent()->attribute('keyword') : '';
$returnArrayChild['tag_name'] = $tag->attribute('keyword');
$returnArrayChild['tag_id'] = (int) $tag->attribute('id');
$returnArray['tags'][] = $returnArrayChild;
}
}
}
return $returnArray;
}
示例3: getChildrenClasses
protected static function getChildrenClasses($parentNodeId)
{
$childrenClassTypes = array();
if ($parentNode = self::getNode($parentNodeId)) {
// ricavo gli identifiers delle classi e le classi
$childrenClassTypes = array();
$childrenClassesParamers = array('SearchSubTreeArray' => array($parentNode->attribute('node_id')), 'SearchLimit' => 1, 'Filter' => array('-meta_id_si:' . $parentNode->attribute('contentobject_id')), 'AsObjects' => false, 'Facet' => array(array('field' => 'meta_class_identifier_ms', 'name' => 'class_identifier', 'limit' => 200)));
$solr = new eZSolr();
$search = $solr->search('', $childrenClassesParamers);
if ($search['SearchCount'] > 0) {
$facets = $search['SearchExtras']->attribute('facet_fields');
$childrenClassTypes = $facets[0]['nameList'];
}
if (!empty($childrenClassTypes)) {
$childrenClassTypes = (array) eZContentClass::fetchList(0, true, false, null, null, $childrenClassTypes);
}
}
return $childrenClassTypes;
}
示例4: suggest
/**
* Provides suggestion results when adding tags to object
*
* @static
*
* @param array $args
*
* @return array
*/
public static function suggest($args)
{
$http = eZHTTPTool::instance();
$searchEngine = eZINI::instance()->variable('SearchSettings', 'SearchEngine');
if (!class_exists('eZSolr') || $searchEngine != 'ezsolr') {
return array('status' => 'success', 'message' => '', 'tags' => array());
}
$tagIDs = $http->postVariable('tag_ids', '');
if (empty($tagIDs)) {
return array('status' => 'success', 'message' => '', 'tags' => array());
}
$tagIDs = array_values(array_unique(explode('|#', $tagIDs)));
$solrSearch = new eZSolr();
$params = array('SearchOffset' => 0, 'SearchLimit' => 0, 'Facet' => array(array('field' => 'ezf_df_tag_ids', 'limit' => 5 + count($tagIDs), 'mincount' => 1)), 'Filter' => array('ezf_df_tag_ids' => implode(' OR ', $tagIDs)), 'QueryHandler' => 'ezpublish', 'AsObjects' => false);
$searchResult = $solrSearch->search('', $params);
if (!isset($searchResult['SearchExtras']) || !$searchResult['SearchExtras'] instanceof ezfSearchResultInfo) {
eZDebug::writeWarning('There was an error fetching tag suggestions from Solr. Maybe server is not running or using unpatched schema?', __METHOD__);
return array('status' => 'success', 'message' => '', 'tags' => array());
}
$facetResult = $searchResult['SearchExtras']->attribute('facet_fields');
if (!is_array($facetResult) || !is_array($facetResult[0]['nameList'])) {
eZDebug::writeWarning('There was an error fetching tag suggestions from Solr. Maybe server is not running or using unpatched schema?', __METHOD__);
return array('status' => 'success', 'message' => '', 'tags' => array());
}
$facetResult = array_values($facetResult[0]['nameList']);
$tagsToSuggest = array();
foreach ($facetResult as $result) {
if (!in_array($result, $tagIDs)) {
$tagsToSuggest[] = $result;
}
}
if (empty($tagsToSuggest)) {
return array('status' => 'success', 'message' => '', 'tags' => array());
}
return self::generateOutput(array('id' => array($tagsToSuggest)), 0, false, $http->postVariable('locale', ''));
}
示例5: search
/**
* Search function
*
* @param string Query string
* @param int Offset
* @param int Limit
* @param array Facet definition
* @param array Filter parameters
* @param array Sort by parameters
* @param mixed Content class ID or list of content class IDs
* @param array list of subtree limitation node IDs
* @param boolean $enableElevation Controls whether elevation should be enabled or not
* @param boolean $forceElevation Controls whether elevation is forced. Applies when the srt criteria is NOT the default one ( 'score desc' ).
*
* @return array Search result
*/
public function search( $query, $offset = 0, $limit = 10, $facets = null,
$filters = null, $sortBy = null, $classID = null, $sectionID = null,
$subtreeArray = null, $ignoreVisibility = null, $limitation = null, $asObjects = true, $spellCheck = null, $boostFunctions = null, $queryHandler = 'ezpublish',
$enableElevation = true, $forceElevation = false, $publishDate = null, $distributedSearch = null, $fieldsToReturn = null, $searchResultClustering = null, $extendedAttributeFilter = array() )
{
$solrSearch = new eZSolr();
$params = array( 'SearchOffset' => $offset,
'SearchLimit' => $limit,
'Facet' => $facets,
'SortBy' => $sortBy,
'Filter' => $filters,
'SearchContentClassID' => $classID,
'SearchSectionID' => $sectionID,
'SearchSubTreeArray' => $subtreeArray,
'AsObjects' => $asObjects,
'SpellCheck' => $spellCheck,
'IgnoreVisibility' => $ignoreVisibility,
'Limitation' => $limitation,
'BoostFunctions' => $boostFunctions,
'QueryHandler' => $queryHandler,
'EnableElevation' => $enableElevation,
'ForceElevation' => $forceElevation,
'SearchDate' => $publishDate,
'DistributedSearch' => $distributedSearch,
'FieldsToReturn' => $fieldsToReturn,
'SearchResultClustering' => $searchResultClustering,
'ExtendedAttributeFilter' => $extendedAttributeFilter );
return array( 'result' => $solrSearch->search( $query, $params ) );
}
示例6: json_encode
// Ultimo giorno (Default)
if (!isset($days)) {
$days = 1;
}
// Tutte le tematiche in OR
$tag_filters = array('or');
foreach ($tematiche as $tag) {
$tag_filters[] = 'attr_tematica_lk: "' . $tag . '"';
}
// Data inizio è di $days giorni indietro
$_startDate = new DateTime();
$_endDate = new DateTime();
$_startDate->modify("-" . $days . " day");
$startDate = ezfSolrDocumentFieldBase::preProcessValue($_startDate->format('U'), 'date');
$endDate = ezfSolrDocumentFieldBase::preProcessValue($_endDate->format('U'), 'date');
// Composizione del filtro
$filters = array('and', 'meta_published_dt:[' . $startDate . ' TO ' . $endDate . ']', $tag_filters);
$params = array('SortBy' => array('meta_published_dt' => 'desc'), 'Filter' => $filters, 'SearchContentClassID' => array($class_id), 'SearchSubTreeArray' => array(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode')));
// Esecuzione query Solr
$solrSearch = new eZSolr();
$result = $solrSearch->search('', $params);
// Estrazione del NodeID
$node_ids = array();
foreach ($result['SearchResult'] as $object) {
$node_ids[] = $object->ContentObject->mainNodeID();
}
// Output in JSON
header('Content-Type: application/json');
echo json_encode($node_ids);
// echo json_encode( $result['SearchResult'] ); // DEBUG
eZExecution::cleanExit();
示例7: fetch
public function fetch($limit = 10, $offset = 0)
{
$fieldsToReturn = array();
foreach (ITNewsletterPost::fields() as $field) {
$fieldsToReturn[] = $field['solr_identifier'];
}
$solrFetchParams = array('SearchOffset' => $offset, 'SearchLimit' => $limit, 'Facet' => $this->facets, 'SortBy' => array('published' => 'desc'), 'Filter' => $this->filters, 'SearchContentClassID' => array(ITNewsletterPost::CLASS_IDENTIFIER), 'SearchSectionID' => null, 'SearchSubTreeArray' => array(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode')), 'AsObjects' => false, 'SpellCheck' => null, 'IgnoreVisibility' => null, 'Limitation' => null, 'BoostFunctions' => null, 'QueryHandler' => 'ezpublish', 'EnableElevation' => true, 'ForceElevation' => true, 'SearchDate' => null, 'DistributedSearch' => null, 'FieldsToReturn' => $fieldsToReturn, 'SearchResultClustering' => null, 'ExtendedAttributeFilter' => array());
$solrSearch = new eZSolr();
$tmp = $solrSearch->search($this->query, $solrFetchParams);
return $tmp;
}
示例8: solrTagCloud
/**
* Returns the tag cloud for specified parameters using eZ Find
*
* @param array $params
*
* @return array
*/
private function solrTagCloud($params)
{
$offset = 0;
if (isset($params['offset']) && is_numeric($params['offset'])) {
$offset = (int) $params['offset'];
}
// It seems that Solr doesn't like PHP_INT_MAX constant on 64bit operating systems
$limit = 1000000;
if (isset($params['limit']) && is_numeric($params['limit'])) {
$limit = (int) $params['limit'];
}
$searchFilter = array();
if (isset($params['class_identifier'])) {
if (!is_array($params['class_identifier'])) {
$params['class_identifier'] = array($params['class_identifier']);
}
if (!empty($params['class_identifier'])) {
$searchFilter['meta_class_identifier_ms'] = '(' . implode(' OR ', $params['class_identifier']) . ')';
}
}
if (isset($params['parent_node_id'])) {
$searchFilter['meta_path_si'] = (int) $params['parent_node_id'];
}
$solrSearch = new eZSolr();
$solrParams = array('SearchOffset' => 0, 'SearchLimit' => 1000000, 'Facet' => array(array('field' => 'ezf_df_tag_ids', 'limit' => 1000000)), 'Filter' => $searchFilter, 'QueryHandler' => 'ezpublish', 'AsObjects' => false);
$searchResult = $solrSearch->search('*:*', $solrParams);
if (!isset($searchResult['SearchExtras']) || !$searchResult['SearchExtras'] instanceof ezfSearchResultInfo) {
return array();
}
$facetResult = $searchResult['SearchExtras']->attribute('facet_fields');
if (!is_array($facetResult) || empty($facetResult[0]['countList'])) {
return array();
}
$tagsCountList = $facetResult[0]['countList'];
/** @var eZTagsObject[] $tags */
$tags = eZTagsObject::fetchList(array('id' => array(array_keys($tagsCountList))));
if (!is_array($tags) || empty($tags)) {
return array();
}
$tagSortArray = array();
$tagKeywords = array();
$tagCounts = array();
foreach ($tags as $tag) {
$tagKeyword = $tag->attribute('keyword');
$tagCount = $tagsCountList[(int) $tag->attribute('id')];
$tagSortArray[] = array('keyword' => $tagKeyword, 'count' => $tagCount, 'tag' => $tag);
$tagKeywords[] = $tagKeyword;
$tagCounts[] = $tagCount;
}
// calling call_user_func_array requires all arguments to be references
// this is the reason for $sortFlags array and $sortArgs[] = &....
$sortArgs = array();
$sortFlags = array(SORT_ASC, SORT_DESC, SORT_LOCALE_STRING, SORT_NUMERIC);
if (isset($params['sort_by']) && is_array($params['sort_by']) && !empty($params['sort_by'])) {
$params['sort_by'] = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by'];
foreach ($params['sort_by'] as $sortItem) {
if (is_array($sortItem) && !empty($sortItem)) {
switch ($sortItem[0]) {
case 'keyword':
$sortArgs[] =& $tagKeywords;
if (isset($sortItem[1]) && $sortItem[1]) {
$sortArgs[] =& $sortFlags[0];
} else {
$sortArgs[] =& $sortFlags[1];
}
$sortArgs[] =& $sortFlags[2];
break;
case 'count':
$sortArgs[] =& $tagCounts;
if (isset($sortItem[1]) && $sortItem[1]) {
$sortArgs[] =& $sortFlags[0];
} else {
$sortArgs[] =& $sortFlags[1];
}
$sortArgs[] =& $sortFlags[3];
break;
}
}
}
}
if (empty($sortArgs)) {
$sortArgs[] =& $tagKeywords;
$sortArgs[] =& $sortFlags[0];
}
$sortArgs[] =& $tagSortArray;
call_user_func_array('array_multisort', $sortArgs);
$tagSortArray = array_slice($tagSortArray, $offset, $limit);
if (empty($tagSortArray)) {
return array();
}
$tagKeywords = array_slice($tagKeywords, $offset, $limit);
$tagCounts = array_slice($tagCounts, $offset, $limit);
if (isset($params['post_sort_by'])) {
//.........这里部分代码省略.........
示例9: search
/**
* Returns search results based on given params
*
* @param mixed $args
* @return array
* @deprecated Use ezjsc::search instead (in ezjscore)
*/
public static function search($args)
{
$http = eZHTTPTool::instance();
if ($http->hasPostVariable('SearchStr')) {
$searchStr = trim($http->postVariable('SearchStr'));
}
$searchOffset = 0;
if ($http->hasPostVariable('SearchOffset')) {
$searchOffset = (int) $http->postVariable('SearchOffset');
}
$searchLimit = 10;
if ($http->hasPostVariable('SearchLimit')) {
$searchLimit = (int) $http->postVariable('SearchLimit');
}
if ($searchLimit > 30) {
$searchLimit = 30;
}
if ($http->hasPostVariable('SearchSubTreeArray') && $http->postVariable('SearchSubTreeArray')) {
$search_sub_tree_array = explode(',', $http->postVariable('SearchSubTreeArray'));
}
//Prepare the search params
$param = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit + 1, 'SortArray' => array('score', 0), 'SearchSubTreeArray' => $search_sub_tree_array);
if ($http->hasPostVariable('enable-spellcheck') and $http->postVariable('enable-spellcheck') == 1) {
$param['SpellCheck'] = array(true);
}
if ($http->hasPostVariable('show-facets') and $http->postVariable('show-facets') == 1) {
$defaultFacetFields = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array());
$param['facet'] = $defaultFacetFields;
}
$solr = new eZSolr();
$searchList = $solr->search($searchStr, $param);
$result = array();
$result['SearchResult'] = eZFlowAjaxContent::nodeEncode($searchList['SearchResult'], array(), false);
$result['SearchCount'] = $searchList['SearchCount'];
$result['SearchOffset'] = $searchOffset;
$result['SearchLimit'] = $searchLimit;
$result['SearchExtras'] = array();
if (isset($param['SpellCheck'])) {
$result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck');
}
if (isset($param['facet'])) {
$facetInfo = array();
$retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields');
$baseSearchUrl = "/content/search/";
eZURI::transformURI($baseSearchUrl, false, 'full');
foreach ($defaultFacetFields as $key => $defaultFacet) {
$facetData = $retrievedFacets[$key];
$facetInfo[$key] = array();
$facetInfo[$key][] = $defaultFacet['name'];
if ($facetData != null) {
foreach ($facetData['nameList'] as $key2 => $facetName) {
$tmp = array();
if ($key2 != '') {
$tmp[] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName;
$tmp[] = $facetName;
$tmp[] = "(" . $facetData['countList'][$key2] . ")";
$facetInfo[$key][] = $tmp;
}
}
}
}
$result['SearchExtras']['facets'] = $facetInfo;
}
return $result;
}
示例10: testSearchSortByPath
/**
* Test for search fetch, results sorted by name
* @link http://issues.ez.no/15423
* @group issue15423
*/
public function testSearchSortByPath()
{
$res = $this->solrSearch->search('', array('SortBy' => array('path', 'asc')) + $this->fetchParams);
self::assertType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res['SearchResult']);
}
示例11: fetch
/**
* @param array $parameters
* @param string $query
*
* @return array
*/
public static function fetch($parameters, $query = '')
{
$solrFetchParams = array('SearchOffset' => 0, 'SearchLimit' => 0, 'Facet' => null, 'SortBy' => null, 'Filter' => null, 'SearchContentClassID' => null, 'SearchSectionID' => null, 'SearchSubTreeArray' => null, 'AsObjects' => true, 'SpellCheck' => null, 'IgnoreVisibility' => null, 'Limitation' => null, 'BoostFunctions' => null, 'QueryHandler' => 'ezpublish', 'EnableElevation' => true, 'ForceElevation' => true, 'SearchDate' => null, 'DistributedSearch' => null, 'FieldsToReturn' => null, 'SearchResultClustering' => null, 'ExtendedAttributeFilter' => array());
$fetchParameters = array_merge($solrFetchParams, $parameters);
$solrSearch = new eZSolr();
return $solrSearch->search($query, $fetchParameters);
}
示例12: eZSolr
}
if (!empty($columnFilters)) {
if (count($columnFilters) > 1) {
$filters[] = array_merge(array('or'), $columnFilters);
} else {
$filters[] = $columnFilters[0];
}
}
}
if (empty($filters)) {
$filters = null;
}
$solrSearch = new eZSolr();
$params = array('SearchOffset' => $iDisplayStart, 'SearchLimit' => $iDisplayLength, 'SortBy' => $sortBy, 'Filter' => $filters, 'SearchContentClassID' => $classes, 'SearchSubTreeArray' => $subtreeArray, 'AsObjects' => false, 'FieldsToReturn' => $fieldsToReturn);
$solrSearch = new eZSolr();
$search = $solrSearch->search($query, $params);
$search['SearchParameters'] = $params;
$iFilteredTotal = count($search['SearchResult']);
$iTotal = $search['SearchCount'];
$output = array("sEcho" => intval($http->getVariable('sEcho')), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iTotal, "aaData" => array());
if (eZINI::instance()->variable('DebugSettings', 'DebugOutput') === 'enabled') {
$output['searchParams'] = $search;
$output['searchQuery'] = $query;
$output['request'] = $_GET;
$output['fields'] = $fields;
$output['results'] = $search['SearchResult'];
}
foreach ($search['SearchResult'] as $item) {
$row = array();
for ($i = 0; $i < count($fields); $i++) {
if ($fields[$i] == 'published' || $fields[$i] == 'published_dt') {
示例13: fetchTimeTableEvents
protected function fetchTimeTableEvents()
{
$events = array();
$filters = array('or', 'attr_timetable_from_time_dt:[' . $this->parameters['search_from_solr'] . ' TO ' . $this->parameters['search_to_solr'] . ']', 'attr_timetable_to_time_dt:[' . $this->parameters['search_from_solr'] . ' TO ' . $this->parameters['search_to_solr'] . ']', array('and', 'attr_timetable_from_time_dt:[* TO ' . $this->parameters['search_from_solr'] . ']', 'attr_timetable_to_time_dt:[' . $this->parameters['search_to_solr'] . ' TO *]'));
$solrFetchParams = array('SearchOffset' => 0, 'SearchLimit' => 1000, 'Filter' => $filters, 'SearchSubTreeArray' => $this->parameters['subtree']);
$solrSearch = new eZSolr();
$solrResult = $solrSearch->search($this->parameters['query'], $solrFetchParams);
foreach ($solrResult['SearchResult'] as $item) {
$events = array_merge($events, OCCalendarTimeTable::getEvents($item, $this->parameters));
}
return $events;
}