本文整理汇总了PHP中Solarium_Client::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Solarium_Client::select方法的具体用法?PHP Solarium_Client::select怎么用?PHP Solarium_Client::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solarium_Client
的用法示例。
在下文中一共展示了Solarium_Client::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: latestRecordsPublications
/** Get the latest records back from solr
*
*/
public function latestRecordsPublications($q = '*:*', $fields = 'id,old_findID,objecttype,imagedir,filename,thumbnail,broadperiod,workflow', $start = 0, $limit = 4, $sort = 'id', $direction = 'desc')
{
$select = array('query' => $q, 'start' => $start, 'rows' => $limit, 'fields' => array($fields), 'sort' => array($sort => $direction), 'filterquery' => array());
if (!in_array($this->getRole(), $this->_allowed)) {
$select['filterquery']['workflow'] = array('query' => 'workflow:[3 TO 4]');
}
$select['filterquery']['images'] = array('query' => 'thumbnail:[1 TO *]');
$cachekey = md5($q . $this->getRole() . 'biblio');
if (!$this->_cache->test($cachekey)) {
$query = $this->_solr->createSelect($select);
$resultset = $this->_solr->select($query);
$data = array();
$data['numberFound'] = $resultset->getNumFound();
foreach ($resultset as $doc) {
$fields = array();
foreach ($doc as $key => $value) {
$fields[$key] = $value;
}
$data['images'][] = $fields;
}
$this->_cache->save($data);
} else {
$data = $this->_cache->load($cachekey);
}
return $this->buildHtml($data);
}
示例2: doSearch
/**
* perform search
* @param WikiaSearchConfig $searchConfig
* @return WikiaSearchResultSet
*/
public function doSearch(WikiaSearchConfig $searchConfig)
{
wfProfileIn(__METHOD__);
if ($searchConfig->getGroupResults() == true) {
$searchConfig->setLength(self::GROUP_RESULTS_GROUPINGS_LIMIT)->setIsInterWiki(true)->setStart((int) $searchConfig->getLength() * ((int) $searchConfig->getPage() - 1));
} else {
$searchConfig->setStart(($searchConfig->getPage() - 1) * $searchConfig->getLength());
}
try {
$result = $this->client->select($this->getSelectQuery($searchConfig));
} catch (Exception $e) {
Wikia::log(__METHOD__, 'Querying Solr First Time', $e);
$searchConfig->setSkipBoostFunctions(true);
try {
$result = $this->client->select($this->getSelectQuery($searchConfig));
} catch (Exception $e) {
Wikia::log(__METHOD__, 'Querying Solr With No Boost Functions', $e);
$result = F::build('Solarium_Result_Select_Empty');
}
}
$results = F::build('WikiaSearchResultSet', array($result, $searchConfig));
$searchConfig->setResults($results)->setResultsFound($results->getResultsFound());
if ($searchConfig->getPage() == 1) {
$resultCount = $results->getResultsFound();
Track::event(!empty($resultCount) ? 'search_start' : 'search_start_nomatch', array('sterm' => $searchConfig->getQuery(), 'rver' => self::RELEVANCY_FUNCTION_ID, 'stype' => $searchConfig->getCityId() == 0 ? 'inter' : 'intra'));
}
wfProfileOut(__METHOD__);
return $results;
}
示例3: indexAction
/** Display of publications with filtration
*/
public function indexAction()
{
$limit = 20;
$page = $this->_getParam('page');
if (!isset($page)) {
$start = 0;
} else {
unset($params['page']);
$start = ($page - 1) * 20;
}
$config = array('adapteroptions' => array('host' => '127.0.0.1', 'port' => 8983, 'path' => '/solr/', 'core' => 'beopublications'));
$select = array('query' => '*:*', 'start' => $start, 'rows' => $limit, 'fields' => array('*'), 'sort' => array('title' => 'asc'), 'filterquery' => array());
$client = new Solarium_Client($config);
// get a select query instance based on the config
$query = $client->createSelect($select);
$resultset = $client->select($query);
$data = NULL;
foreach ($resultset as $doc) {
foreach ($doc as $key => $value) {
$fields[$key] = $value;
}
$data[] = $fields;
}
$paginator = Zend_Paginator::factory($resultset->getNumFound());
$paginator->setCurrentPageNumber($page)->setItemCountPerPage($limit)->setPageRange(20);
$this->view->paginator = $paginator;
$this->view->results = $data;
}
示例4: getRecords
/** Get records from solr
* @access public
* @return array
*/
public function getRecords($cursor = 0, $set, $from, $until)
{
$fields = array('id', 'old_findID', 'creator', 'description', 'broadperiod', 'thumbnail', 'imagedir', 'filename', 'created', 'institution', 'updated', 'objecttype', 'fourFigure', 'fromdate', 'todate', 'county', 'district', 'materialTerm', 'knownas', 'secondaryMaterialTerm', 'fourFigureLat', 'fourFigureLon');
$select = array('query' => '*:*', 'start' => $cursor, 'rows' => self::LISTLIMIT, 'fields' => $fields, 'sort' => array('created' => 'asc'), 'filterquery' => array());
if (!in_array($this->getRole(), $this->_allowed)) {
$select['filterquery']['workflow'] = array('query' => 'workflow:[3 TO 4]');
}
if (isset($set)) {
$select['filterquery']['set'] = array('query' => 'institution:' . $set);
}
if (isset($from)) {
$select['filterquery']['from'] = array('query' => 'created:[' . $this->todatestamp($from) . ' TO * ]');
}
if (isset($until)) {
$select['filterquery']['until'] = array('query' => 'created:[* TO ' . $this->todatestamp($until) . ']');
}
$query = $this->_solr->createSelect($select);
$resultset = $this->_solr->select($query);
$data = array();
$data['numberFound'] = $resultset->getNumFound();
foreach ($resultset as $doc) {
$fields = array();
foreach ($doc as $key => $value) {
$fields[$key] = $value;
}
$data['finds'][] = $fields;
}
return $data;
}
示例5: getIds
protected function getIds()
{
$client = new Solarium_Client($this->CONFIG);
$select = $client->createSelect();
$select->setRows(20000);
$select->createFilterQuery('users')->setQuery('activeusers:[0 TO *]');
$select->createFilterQuery('pages')->setQuery('wikipages:[500 TO *]');
$select->createFilterQuery('words')->setQuery('words:[10 TO *]');
$select->createFilterQuery('ns')->setQuery('ns:0');
$select->createFilterQuery('wam')->setQuery('-(wam:0)');
$select->createFilterQuery('dis')->setQuery('-(title_en:disambiguation)');
$select->createFilterQuery('answer_host')->setQuery('-(host:*answers.wikia.com)');
$select->createFilterQuery('answer')->setQuery('-(hub:Wikianswers)');
//speedydeletion: 547090, scratchpad: 95, lyrics:43339, colors:32379
$select->createFilterQuery('banned')->setQuery('-(wid:547090) AND -(wid:95) AND -(wid:43339) AND -(wid:32379)');
// faceting would be less expensive
$select->addParam('group', 'true');
$select->addParam('group.field', 'wid');
$select->addParam('group.ngroups', 'true');
$result = $client->select($select);
$ids = [];
if (isset($result->getData()['grouped']['wid']['groups'])) {
foreach ($result->getData()['grouped']['wid']['groups'] as $group) {
$ids[] = $group['groupValue'];
}
}
return $ids;
}
示例6: getSolrResults
/** Get the solr data
* @access public
* @return array
*/
public function getSolrResults()
{
$query = $this->_solr->createSelect();
$query->setRows(0);
$stats = $query->getStats();
$stats->createField('quantity');
$resultset = $this->_solr->select($query);
$data = $resultset->getStats();
$stats = array();
// Create array of data for use in partial
foreach ($data as $result) {
$stats['total'] = $result->getSum();
$stats['records'] = $result->getCount();
}
return $stats;
}
示例7: listPageCounts
/**
* @param integer $start
* @param integer $count
* @return array
*/
public function listPageCounts($start, $count)
{
$query = $this->solariumClient->createSelect();
$query->setQuery("(ns:0)");
$query->getGrouping()->addField("wid");
$query->setStart($start);
$query->setRows($count);
$query->addSort('wid', Solarium_Query_Select::SORT_ASC);
$resultSet = $this->solariumClient->select($query);
$results = [];
foreach ($resultSet->getGrouping()->getGroups() as $group) {
/** @var Solarium_Result_Select_Grouping_FieldGroup $group */
foreach ($group as $groupElement) {
/** @var Solarium_Result_Select_Grouping_ValueGroup $groupElement */
$results[] = new WikiPageCountModel($groupElement->getValue(), $groupElement->getNumFound());
}
}
return $results;
}
示例8: getSMRSNearbyFinds
/** Find objects recorded with proximity to SMRs within a certain distance
* of a lat lon pair, this is set up to work in kilometres from point. You
* can adapt this for miles. This perhaps can be swapped out for a SOLR
* based search in future.
* @access public
* @param double $lat
* @param double $long
* @param integer $distance
* @return array
*/
public function getSMRSNearbyFinds($lat, $lon, $distance)
{
$config = $this->_config->solr->asgard->toArray();
$config['core'] = 'objects';
$solr = new Solarium_Client(array('adapteroptions' => $config));
$select = array('query' => '*:*', 'fields' => array('*'), 'filterquery' => array());
$query = $solr->createSelect($select);
$helper = $query->getHelper();
$query->createFilterQuery('geofilt')->setQuery($helper->geofilt($lat, $lon, 'coordinates', $distance));
$resultset = $solr->select($query);
$data = array();
foreach ($resultset as $document) {
$data[] = array('id' => $document['id'], 'old_findID' => $document['old_findID'], 'county' => $document['county'], 'broadperiod' => $document['broadperiod']);
}
return $data;
}
示例9: searchLyrics
/**
* @desc Searches for a song lyrics in Solr index
*
* @param LyricsApiSearchParams $searchParams
*
* @return array|null
*/
public function searchLyrics(LyricsApiSearchParams $searchParams)
{
$query = $this->newQueryFromSearch(['type: %1%' => LyricsUtils::TYPE_SONG, 'lyrics: %P2%' => $searchParams->getField(LyricsApiController::PARAM_QUERY)]);
$query->setStart($searchParams->getOffset());
$query->setRows($searchParams->getLimit());
$hl = $query->getHighlighting();
$hl->setFields(self::INDEX_FIELD_NAME_LYRICS);
$hl->setSimplePrefix(self::HIGHLIGHT_PREFIX);
$hl->setSimplePostfix(self::HIGHLIGHT_POSTFIX);
$solrSongs = $this->client->select($query);
if ($solrSongs->getNumFound() <= 0) {
return null;
}
$songs = [];
$highlighting = $solrSongs->getHighlighting();
/** @var Solarium_Document_ReadOnly $solrSong */
foreach ($solrSongs as $solrSong) {
$fields = $solrSong->getFields();
$songs[] = $this->getOutputSong($solrSong, $highlighting->getResult($fields['id']), true);
}
return $songs;
}
示例10: foreach
<?php
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require 'init.php';
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// set the adapter to curl
$client->setAdapter('Solarium_Client_Adapter_Curl');
// get a select query instance
$query = $client->createSelect();
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: ' . $resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach ($document as $field => $value) {
// this converts multivalue fields to a comma-separated string
if (is_array($value)) {
$value = implode(', ', $value);
}
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
示例11: handle
function handle($args)
{
/*
* Make sure we have a search term.
*/
if (!isset($args['term']) || empty($args['term'])) {
json_error('Search term not provided.');
die;
}
/*
* Clean up the search term.
*/
$term = filter_var($args['term'], FILTER_SANITIZE_STRING);
/*
* Determine if the search results should display detailed information about each law.
*/
if (!isset($_GET['detailed']) || empty($_GET['detailed'])) {
$detailed = FALSE;
} else {
$detailed = filter_var($_GET['detailed'], FILTER_SANITIZE_STRING);
if ($detailed == "true") {
$detailed = TRUE;
} elseif ($detailed != "false") {
$detailed = FALSE;
} else {
$detailed = FALSE;
}
}
/*
* Intialize Solarium.
*/
$client = new Solarium_Client($GLOBALS['solr_config']);
/*
* Set up our query.
*/
$query = $client->createSelect();
$query->setQuery($term);
/*
* We want the most useful bits extracted as search results snippets.
*/
$hl = $query->getHighlighting();
$hl->setFields('catch_line, text');
/*
* Specify that we want the first 100 results.
*/
$query->setStart(0)->setRows(100);
/*
* Execute the query.
*/
$search_results = $client->select($query);
/*
* Display uses of the search terms in a preview of the result.
*/
$highlighted = $search_results->getHighlighting();
/*
* If there are no results.
*/
if (count($search_results) == 0) {
$response->records = 0;
$response->total_records = 0;
}
/*
* If we have results.
*/
/*
* Instantiate the Law class.
*/
$law = new Law();
/*
* Save an array of the legal code's structure, which we'll use to properly identify the structural
* data returned by Solr. We hack off the last element of the array, since that identifies the laws
* themselves, not a structural unit.
*/
$code_structures = array_slice(explode(',', STRUCTURE), 0, -1);
$i = 0;
foreach ($search_results as $document) {
/*
* Attempt to display a snippet of the indexed law.
*/
$snippet = $highlighted->getResult($document->id);
if ($snippet != FALSE) {
/*
* Build the snippet up from the snippet object.
*/
foreach ($snippet as $field => $highlight) {
$response->results->{$i}->excerpt .= strip_tags(implode(' ... ', $highlight)) . ' ... ';
}
/*
* Use an appropriate closing ellipsis.
*/
if (substr($response->results->{$i}->excerpt, -6) == '. ... ') {
$response->results->{$i}->excerpt = substr($response->results->{$i}->excerpt, 0, -6) . '....';
}
$response->results->{$i}->excerpt = trim($response->results->{$i}->excerpt);
}
/*
* At the default level of verbosity, just give the data indexed by Solr, plus the URL.
*/
if ($detailed === FALSE) {
/*
//.........这里部分代码省略.........
示例12: StdClass
/**
* Get a collection of the laws most similar to the present law.
*/
function get_related()
{
/*
* The number of results to return. The default is 5.
*/
if (!isset($this->num_results)) {
$this->num_results = 5;
}
/*
* Intialize Solarium.
*/
$client = new Solarium_Client($GLOBALS['solr_config']);
if ($client === FALSE) {
return FALSE;
}
/*
* Create a MoreLikeThis query instance.
*/
$query = $client->createMoreLikeThis();
/*
* Note that we have to escape colons in this query.
*/
$query->setQuery('section:' . str_replace(':', '\\:', $this->section_number));
$query->setMltFields('text,tags,catch_line');
$query->setMatchInclude(TRUE);
$query->setStart(0)->setRows($this->num_results);
/*
* Execute the query and return the result.
*/
$results = $client->select($query);
/*
* If our query fails.
*/
if ($results === FALSE) {
return FALSE;
}
/*
* Create a new, blank object to store our related sections.
*/
$related = new StdClass();
/*
* Iterate through the returned documents
*/
$i = 0;
foreach ($results as $document) {
$law = new Law();
$law->law_id = $document->id;
$law->get_law();
$related->{$i} = $law;
$i++;
}
return TRUE;
}
示例13: queryPhraseForWikias
public function queryPhraseForWikias($query, $hubs, $lang)
{
$fields = ["url", "lang_s", "sitename_txt", "id", "score", "description_txt"];
$config = (new Factory())->getSolariumClientConfig();
$config['adapteroptions']['core'] = 'xwiki';
$client = new \Solarium_Client($config);
$phrase = $this->sanitizeQuery($query);
$query = $this->prepareXWikiQuery($phrase, $hubs, $lang);
$select = $client->createSelect();
$dismax = $select->getDisMax();
$dismax->setQueryParser('edismax');
$select->setQuery($query);
$select->setRows(self::CROSS_WIKI_RESULTS);
//filter queries
$select->createFilterQuery('wam')->setQuery('-(wam_i:0)');
$select->createFilterQuery('users')->setQuery('activeusers_i:[0 TO *]');
$select->createFilterQuery('pages')->setQuery('articles_i:[50 TO *]');
//speedydeletion: 547090, scratchpad: 95, lyrics:43339,
$select->createFilterQuery('banned')->setQuery('-(id:547090) AND -(id:95) AND -(id:43339) AND -(hostname_s:*answers.wikia.com)');
$dismax->setBoostQuery('domains_txt:"www.' . preg_replace('|\\s*|', '', $phrase) . '.wikia.com"^1000');
$dismax->setBoostFunctions('wam_i^5 articles_i^0.5');
$result = $client->select($select);
return $this->extractData($result, $fields);
}
示例14: resultsAction
/** Display the index page.
*/
public function resultsAction()
{
$params = array_slice($this->_getAllParams(), 3);
if (sizeof($params) > 0) {
$limit = 20;
$page = $this->_getParam('page');
if (!isset($page)) {
$start = 0;
} else {
unset($params['page']);
$start = ($page - 1) * 20;
}
$q = '';
if (array_key_exists('q', $params)) {
$q .= $params['q'] . ' ';
unset($params['q']);
}
if (array_key_exists('images', $params)) {
$images = (int) 1;
unset($params['images']);
}
if (array_key_exists('radius', $params)) {
$d = (int) $params['radius'];
unset($params['radius']);
}
if (array_key_exists('lat', $params)) {
$lat = (double) $params['lat'];
unset($params['lat']);
}
if (array_key_exists('lon', $params)) {
$lon = (double) $params['lon'];
unset($params['lon']);
}
$params = array_filter($params);
foreach ($params as $k => $v) {
$q .= $k . ':"' . $v . '" ';
}
$config = array('adapteroptions' => array('host' => '127.0.0.1', 'port' => 8983, 'path' => '/solr/', 'core' => 'beowulf'));
$select = array('query' => $q, 'start' => $start, 'rows' => $limit, 'fields' => array('*'), 'sort' => array('created' => 'desc'), 'filterquery' => array());
$allowed = array('fa', 'flos', 'admin', 'treasure');
if (!in_array($this->getRole(), $allowed)) {
$select['filterquery']['workflow'] = array('query' => 'workflow:[3 TO *]');
if (array_key_exists('parish', $params)) {
$select['filterquery']['knownas'] = array('query' => 'knownas:["" TO *]');
}
}
if (!is_null($images)) {
$select['filterquery']['images'] = array('query' => 'thumbnail:[1 TO *]');
}
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance based on the config
$query = $client->createSelect($select);
if (!is_null($d) && !is_null($lon) && !is_null($lat)) {
$helper = $query->getHelper();
$query->createFilterQuery('geo')->setQuery($helper->geofilt($lat, $lon, 'coordinates', $d));
}
$facetSet = $query->getFacetSet();
$facetSet->createFacetField('period')->setField('broadperiod');
$facetSet->createFacetField('county')->setField('county');
$facetSet->createFacetField('objectType')->setField('objectType');
$resultset = $client->select($query);
$pagination = array('page' => $page, 'per_page' => $limit, 'total_results' => $resultset->getNumFound());
$data = NULL;
foreach ($resultset as $doc) {
$fields = array();
foreach ($doc as $key => $value) {
$fields[$key] = $value;
}
$data[] = $fields;
}
// Zend_Debug::dump($data);
// $periodFacet = $resultset->getFacetSet()->getFacet('period');
// foreach($periodFacet as $value => $count) {
// echo $value . ' [' . $count . ']<br/>';
// }
// $objectFacet = $resultset->getFacetSet()->getFacet('objectType');
// foreach($objectFacet as $value => $count) {
// echo $value . ' [' . $count . ']<br/>';
// }
// $countyFacet = $resultset->getFacetSet()->getFacet('county');
// foreach($countyFacet as $value => $count) {
// echo $value . ' [' . $count . ']<br/>';
// }
$paginator = Zend_Paginator::factory($resultset->getNumFound());
$paginator->setCurrentPageNumber($page)->setItemCountPerPage($limit)->setPageRange(20);
$this->view->paginator = $paginator;
$this->view->results = $data;
} else {
throw new Pas_Exception_Param('Your search has no parameters!', 500);
}
}
示例15: findnearestAction
/** Find nearest staff member from solr
* @access public
* @return void
* @todo finish function
*/
public function findnearestAction()
{
$postcode = new Pas_Service_Geo_PostCodeToGeo();
$geo = $postcode->getData('WC1B 3DG');
$config = $this->_helper->config()->solr->toArray();
$config['core'] = 'objects';
$client = new Solarium_Client(array('adapteroptions' => $config));
// get a select query instance and a query helper instance
$select = array('query' => '*:*', 'fields' => array('*'), 'filterquery' => array());
$query = $client->createSelect($select);
$helper = $query->getHelper();
// add a filterquery on a price range, using the helper to generate the range
$query->createFilterQuery('geodist')->setQuery($helper->geodist($geo['lat'], $geo['lon'], 'coordinates'));
$resultset = $client->select($query);
Zend_Debug::dump($resultset);
}