本文整理汇总了PHP中Solarium_Client类的典型用法代码示例。如果您正苦于以下问题:PHP Solarium_Client类的具体用法?PHP Solarium_Client怎么用?PHP Solarium_Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Solarium_Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: delete
/** Delete record by ID
*
* @param $id
*/
public function delete($id)
{
$solr = new Solarium_Client(array('adapteroptions' => array('host' => '127.0.0.1', 'port' => 8983, 'path' => '/solr/', 'core' => 'beowulf')));
$update = $solr->createUpdate();
$update->addDeleteById('findIdentifier-' . $id);
$update->addCommit();
$result = $solr->update($update);
}
示例4: 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);
/*
* Append an asterix to the search term, so that Solr can suggest autocomplete terms.
*/
$term .= '*';
/*
* Intialize Solarium.
*/
$client = new Solarium_Client($GLOBALS['solr_config']);
/*
* Set up our query.
*/
$query = $client->createSuggester();
$query->setHandler('suggest');
$query->setQuery($term);
$query->setOnlyMorePopular(TRUE);
$query->setCount(5);
$query->setCollate(TRUE);
/*
* Execute the query.
*/
$search_results = $client->suggester($query);
/*
* If there are no results.
*/
if (count($search_results) == 0) {
$response->terms = FALSE;
} else {
$response->terms = array();
foreach ($search_results as $term => $term_result) {
$i = 0;
foreach ($term_result as $suggestion) {
$response->terms[] = array('id' => $i, 'term' => $suggestion);
$i++;
}
}
}
$this->render($response, 'OK');
}
示例5: __construct
/** The constructor
*
*/
public function __construct()
{
$this->_cache = Zend_Registry::get('cache');
$this->_config = Zend_Registry::get('config');
$this->_solrConfig = array('adapteroptions' => $this->_config->solr->toArray());
$this->_solr = new Solarium_Client($this->_solrConfig);
$this->_solr->setAdapter('Solarium_Client_Adapter_ZendHttp');
$loadbalancer = $this->_solr->getPlugin('loadbalancer');
$master = $this->_config->solr->master->toArray();
$slave = $this->_config->solr->slave->toArray();
$loadbalancer->addServer('master', $master, 100);
$loadbalancer->addServer('slave', $slave, 200);
$loadbalancer->setFailoverEnabled(true);
}
示例6: 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;
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$parts = parse_url($input->getArgument('url'));
$config = array('adapteroptions' => array('host' => $parts['host'], 'port' => isset($parts['port']) ? $parts['port'] : 80, 'path' => $parts['path']));
$client = new \Solarium_Client($config);
$ping = $client->createPing();
$q_start = microtime(TRUE);
$response = $client->execute($ping);
$client_query_time = round((microtime(TRUE) - $q_start) * 1000, 1) . 'ms';
$body = $response->getResponse()->getBody();
if (!empty($body)) {
$data = json_decode($body);
$status = isset($data->status) ? $data->status : 'Unknown';
$server_query_time = isset($data->responseHeader->QTime) ? $data->responseHeader->QTime . 'ms' : 'Unknown';
$output->writeln("Ping status {$status} completed in (client/server) {$client_query_time}/{$server_query_time}");
}
}
示例8: testCreateQueryPostPlugin
public function testCreateQueryPostPlugin()
{
$type = Solarium_Client::QUERYTYPE_SELECT;
$options = array('optionA' => 1, 'optionB' => 2);
$query = $this->_client->createQuery($type, $options);
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client, array()));
$observer->expects($this->once())->method('postCreateQuery')->with($this->equalTo($type), $this->equalTo($options), $this->equalTo($query));
$this->_client->registerPlugin('testplugin', $observer);
$this->_client->createQuery($type, $options);
}
示例9: getSolr
/** Get the solr object for querying cores
* @access public
* @return \Solarium_Client
*/
public function getSolr()
{
$this->_solr = new Solarium_Client($this->getSolrConfig());
$this->_solr->setAdapter('Solarium_Client_Adapter_ZendHttp');
$this->_solr->getAdapter()->getZendHttp();
$loadbalancer = $this->_solr->getPlugin('loadbalancer');
$master = $this->getConfig()->solr->master->toArray();
$asgard = $this->getConfig()->solr->asgard->toArray();
$valhalla = $this->getConfig()->solr->valhalla->toArray();
$loadbalancer->addServer('objects', $master, 100);
$loadbalancer->addServer('asgard', $asgard, 200);
$loadbalancer->addServer('valhalla', $valhalla, 150);
$loadbalancer->setFailoverEnabled(true);
$this->_solr->getAdapter()->getZendHttp();
$this->_loadbalancer = $loadbalancer;
return $this->_solr;
}
示例10: testFailoverMaxRetries
public function testFailoverMaxRetries()
{
$this->_plugin = new TestLoadbalancer();
// special loadbalancer that returns servers in fixed order
$this->_client = new Solarium_Client();
$adapter = new TestAdapterForFailover();
$adapter->setFailCount(10);
$this->_client->setAdapter($adapter);
// set special mock that fails for all servers
$this->_plugin->init($this->_client, array());
$request = new Solarium_Client_Request();
$servers = array('s1' => array('options' => $this->_serverOptions, 'weight' => 1), 's2' => array('options' => $this->_serverOptions, 'weight' => 1));
$this->_plugin->setServers($servers);
$this->_plugin->setFailoverEnabled(true);
$query = new Solarium_Query_Select();
$this->_plugin->preCreateRequest($query);
$this->setExpectedException('Solarium_Exception', 'Maximum number of loadbalancer retries reached');
$this->_plugin->preExecuteRequest($request);
}
示例11: htmlHeader
<?php
require 'init.php';
htmlHeader();
// This example shows how to manually execute the query flow.
// By doing this manually you can customize data in between any step (although a plugin might be better for this)
// And you can use only a part of the flow. You could for instance use the query object and request builder,
// but execute the request in your own code.
// create a client instance
$client = new Solarium_Client($config);
// create a select query instance
$query = $client->createSelect();
// manually create a request for the query
$request = $client->createRequest($query);
// you can now use the request object for getting an uri (ie. to use in you own code)
// or you could modify the request object
echo 'Request URI: ' . $request->getUri() . '<br/>';
// you can still execute the request using the client and get a 'raw' response object
$response = $client->executeRequest($request);
// and finally you can convert the response into a result
$result = $client->createResult($query, $response);
// display the total number of documents found by solr
echo 'NumFound: ' . $result->getNumFound();
// show documents using the resultset iterator
foreach ($result 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);
示例12: deleteBundlesIndexes
/**
* Delete all bundles from index
*/
public function deleteBundlesIndexes(Bundle $bundle = null)
{
$delete = $this->solarium->createUpdate();
$delete->addDeleteQuery(null !== $bundle ? $bundle->getFullName() : '*:*');
$delete->addCommit();
$this->solarium->update($delete);
}
示例13: 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);
}
示例14: testPostCreateRequestUnalteredPostRequest
public function testPostCreateRequestUnalteredPostRequest()
{
$query = $this->_client->createUpdate();
$query->addDeleteById(1);
$requestOutput = $this->_client->createRequest($query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($query, $requestOutput);
$this->assertEquals($requestInput, $requestOutput);
}
示例15: 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;
}