本文整理汇总了PHP中Solarium_Client::createSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Solarium_Client::createSelect方法的具体用法?PHP Solarium_Client::createSelect怎么用?PHP Solarium_Client::createSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solarium_Client
的用法示例。
在下文中一共展示了Solarium_Client::createSelect方法的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: 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;
}
示例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: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: getSong
/**
* @desc Gets a song from Solr index if exists
*
* @param LyricsApiSearchParams $searchParams
*
* @return null|stdClass
*/
public function getSong(LyricsApiSearchParams $searchParams)
{
$query = $this->client->createSelect();
$lowerCaseSongName = $searchParams->getLowerCaseField(LyricsApiController::PARAM_SONG);
$queryText = 'type:%1% AND artist_name_lc:%P2% AND ( song_name_lc:%P3% OR song_name_lc:%P4% )';
$params = [LyricsUtils::TYPE_SONG, $searchParams->getLowerCaseField(LyricsApiController::PARAM_ARTIST), $lowerCaseSongName, LyricsUtils::removeBrackets($lowerCaseSongName)];
$query->setQuery($queryText, $params);
$query->setFields(['artist_name', 'album_id', 'album_name', 'song_name', 'image', 'itunes', self::INDEX_FIELD_NAME_LYRICS]);
$query->setStart(0)->setRows(1);
$solrSong = $this->getFirstResult($this->client->select($query));
if (is_null($solrSong)) {
return null;
}
return $this->getOutputSong($solrSong);
}
示例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: getNestedQuery
/**
* Creates a nested query using dismax.
* @see WikiaSearchTest::testGetNestedQuery
* @param WikiaSearchConfig $searchConfig
* @return Solarium_Query_Select
*/
private function getNestedQuery(WikiaSearchConfig $searchConfig)
{
wfProfileIn(__METHOD__);
$nestedQuery = $this->client->createSelect();
$nestedQuery->setQuery($searchConfig->getQuery());
$dismax = $nestedQuery->getDismax();
$boostQueryString = $this->getBoostQueryString($searchConfig);
$queryFieldsString = $this->getQueryFieldsString($searchConfig);
$dismax->setQueryFields($queryFieldsString)->setQueryParser('edismax');
if ($this->wg->SharedExternalDB !== null) {
$dismax->setPhraseFields($queryFieldsString)->setBoostQuery($this->getBoostQueryString($searchConfig))->setMinimumMatch($searchConfig->getMinimumMatch())->setPhraseSlop(3)->setTie(0.01);
if (!$searchConfig->getSkipBoostFunctions()) {
$dismax->setBoostFunctions(implode(' ', $searchConfig->isInterWiki() ? $this->interWikiBoostFunctions : $this->onWikiBoostFunctions));
}
}
wfProfileOut(__METHOD__);
return $nestedQuery;
}
示例10: getResultMock
private function getResultMock($responseType)
{
$client = new \Solarium_Client();
$mock = new \Solarium_Result_Select($client, $client->createSelect(), $this->{$responseType}());
return $mock;
}
示例11: 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);
}
示例12: 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);
}
}
示例13: array
<?php
require 'init.php';
htmlHeader();
// In this case an array is used for configuration to keep the example simple.
// For an easier to use config file you are probably better of with another format, like Zend_Config_Ini
// See the documentation for more info about this.
$select = array('query' => '*:*', 'start' => 2, 'rows' => 20, 'fields' => array('id', 'name', 'price'), 'sort' => array('price' => 'asc'), 'filterquery' => array('maxprice' => array('query' => 'price:[1 TO 300]')), 'component' => array('facetset' => array('facet' => array(array('type' => 'field', 'key' => 'stock', 'field' => 'inStock')))));
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance based on the config
$query = $client->createSelect($select);
// 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();
// display facet counts
echo '<hr/>Facet counts for field "inStock":<br/>';
$facet = $resultset->getFacetSet()->getFacet('stock');
foreach ($facet as $value => $count) {
echo $value . ' [' . $count . ']<br/>';
}
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
echo '<tr><th>id</th><td>' . $document->id . '</td></tr>';
echo '<tr><th>name</th><td>' . $document->name . '</td></tr>';
echo '<tr><th>price</th><td>' . $document->price . '</td></tr>';
echo '</table>';
}
htmlFooter();
示例14: microtime
<?php
require 'init.php';
htmlHeader();
// create a client instance and autoload the customize request plugin
$client = new Solarium_Client($config);
$parallel = $client->getPlugin('parallelexecution');
// Add a delay param to better show the effect, as an example Solr install with
// only a dozen documents is too fast for good testing
// This param only works with the correct Solr plugin,
// see http://www.raspberry.nl/2012/01/04/solr-delay-component/
// If you don't have to plugin the example still works, just without the delay.
$customizer = $client->getPlugin('customizerequest');
$customizer->createCustomization(array('key' => 'delay', 'type' => 'param', 'name' => 'delay', 'value' => '500', 'persistent' => true));
// create two queries to execute in an array. Keys are important for fetching the results later!
$queryInstock = $client->createSelect()->setQuery('inStock:true');
$queryLowprice = $client->createSelect()->setQuery('price:[1 TO 300]');
// first execute the queries the normal way and time it
$start = microtime(true);
$client->execute($queryInstock);
$client->execute($queryLowprice);
echo 'Execution time for normal "serial" execution of two queries: ' . round(microtime(true) - $start, 3);
echo '<hr/>';
// now execute the two queries parallel and time it
$start = microtime(true);
$parallel->addQuery('instock', $queryInstock);
$parallel->addQuery('lowprice', $queryLowprice);
$results = $parallel->execute();
echo 'Execution time for parallel execution of two queries: ' . round(microtime(true) - $start, 3);
htmlFooter();
// Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is
示例15: setUp
public function setUp()
{
$this->_plugin = new Solarium_Plugin_PrefetchIterator();
$this->_client = new Solarium_Client();
$this->_query = $this->_client->createSelect();
}