本文整理汇总了PHP中Elastica\Search::search方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::search方法的具体用法?PHP Search::search怎么用?PHP Search::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Search
的用法示例。
在下文中一共展示了Search::search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getItems
/**
* {@inheritDoc}
*
* @api
*/
public function getItems($offset, $limit)
{
$query = $this->search->getQuery();
$query->setFrom($offset);
$query->setSize($limit);
return $this->search->search()->getResults();
}
示例2: findByCriteria
public function findByCriteria(TrackRepositoryCriteria $criteria)
{
$boolQuery = new \Elastica\Query\BoolQuery();
if ($criteria->albumId()) {
$query = new \Elastica\Query\Term();
$query->setParam('album.id', $criteria->albumId());
$boolQuery->addMust($query);
}
if ($criteria->albumTitle()) {
$query = new \Elastica\Query\Match();
$query->setFieldQuery('album.title', $criteria->albumTitle());
$query->setFieldFuzziness('album.title', 2);
$boolQuery->addMust($query);
}
if ($criteria->trackName()) {
$query = new \Elastica\Query\Match();
$query->setFieldQuery('name', $criteria->trackName());
$query->setFieldFuzziness('name', 2);
$boolQuery->addMust($query);
}
if ($criteria->composer()) {
$query = new \Elastica\Query\Match();
$query->setFieldQuery('composer', $criteria->composer());
$query->setFieldFuzziness('composer', 2);
$boolQuery->addMust($query);
}
$this->elasticaSearch->setQuery($boolQuery);
$query = $this->elasticaSearch->getQuery();
$query->setSize($criteria->size());
$query->setFrom(($criteria->page() - 1) * $criteria->size());
$query->addSort(['name_not_analyzed' => ['order' => 'asc']]);
return $this->buildEntities($this->elasticaSearch->search()->getResults());
}
示例3: testHasParent
/**
* @group functional
*/
public function testHasParent()
{
$index = $this->_createIndex();
$shopType = $index->getType('shop');
$productType = $index->getType('product');
$mapping = new Mapping();
$mapping->setParent('shop');
$productType->setMapping($mapping);
$shopType->addDocuments(array(new Document('zurich', array('brand' => 'google')), new Document('london', array('brand' => 'apple'))));
$doc1 = new Document(1, array('device' => 'chromebook'));
$doc1->setParent('zurich');
$doc2 = new Document(2, array('device' => 'macmini'));
$doc2->setParent('london');
$productType->addDocument($doc1);
$productType->addDocument($doc2);
$index->refresh();
// All documents
$parentQuery = new HasParent(new MatchAll(), $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(2, $results->count());
$match = new Match();
$match->setField('brand', 'google');
$parentQuery = new HasParent($match, $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(1, $results->count());
$result = $results->current();
$data = $result->getData();
$this->assertEquals($data['device'], 'chromebook');
}
示例4: doSearch
/**
* Run a search.
*
* @param Query $q
* @return ResultSet
*/
protected function doSearch(Query $q)
{
$search = new Search($this->client);
$search->addIndex('bash')->addType('bash');
$search->setQuery($q);
return $search->search();
}
示例5: testShouldReturnTheRightNumberOfResult
/**
* @group functional
*/
public function testShouldReturnTheRightNumberOfResult()
{
$filter = new Nested();
$this->assertEquals(array('nested' => array()), $filter->toArray());
$query = new Terms();
$query->setTerms('hobby', array('guitar'));
$filter->setPath('hobbies');
$filter->setFilter($query);
$client = $this->_getClient();
$search = new Search($client);
$index = $this->_getIndexForTest();
$search->addIndex($index);
$resultSet = $search->search($filter);
$this->assertEquals(1, $resultSet->getTotalHits());
$filter = new Nested();
$this->assertEquals(array('nested' => array()), $filter->toArray());
$query = new Terms();
$query->setTerms('hobby', array('opensource'));
$filter->setPath('hobbies');
$filter->setFilter($query);
$client = $this->_getClient();
$search = new Search($client);
$index = $this->_getIndexForTest();
$search->addIndex($index);
$resultSet = $search->search($filter);
$this->assertEquals(2, $resultSet->getTotalHits());
}
示例6: Search
function get_limit($start, $count)
{
$this->query->from($start);
$this->query->size($count);
$search = new Search($this->client);
return $search->search($this->query->toArray())->getResults();
}
示例7: getSearchResult
/**
* @return \Elastica\ResultSet
*/
public function getSearchResult()
{
$index = $this->search->getIndex($this->getIndexName() . '_' . $this->language);
$search = new Search($this->search->getClient());
$search->addIndex($index);
$search->addType($index->getType($this->indexType));
$result = $search->search($this->query);
return $result;
}
示例8: show
/**
* Perform the show action for a block
*
* @param ReadBlockInterface $block
*
* @return Response
*/
public function show(ReadBlockInterface $block)
{
$request = $this->requestStack->getCurrentRequest();
$data = $request->get('elastica_search');
$searchData = array();
if (is_array($data) && array_key_exists('search', $data) && null !== $data['search']) {
$searchParameter = $data['search'];
$index = $this->client->getIndex($this->indexName);
$qb = new QueryBuilder();
$search = new Search($this->client);
$search->addIndex($index);
$search->setQuery($qb->query()->filtered($qb->query()->query_string($searchParameter), $qb->filter()->bool()->addMust($qb->filter()->term(array('language' => $request->getLocale())))));
$searchData = $search->search(null, array('limit' => $block->getAttribute('searchLimit')));
}
return $this->render('OpenOrchestraElasticaFrontBundle:Block/List:show.html.twig', array('searchData' => $searchData));
}
示例9: testMatchAllIndicesTypes
/**
* @group functional
*/
public function testMatchAllIndicesTypes()
{
$index1 = $this->_createIndex();
$index2 = $this->_createIndex();
$client = $index1->getClient();
$search1 = new Search($client);
$resultSet1 = $search1->search(new MatchAll());
$doc1 = new Document(1, array('name' => 'ruflin'));
$doc2 = new Document(1, array('name' => 'ruflin'));
$index1->getType('test')->addDocument($doc1);
$index2->getType('test')->addDocument($doc2);
$index1->refresh();
$index2->refresh();
$search2 = new Search($client);
$resultSet2 = $search2->search(new MatchAll());
$this->assertEquals($resultSet1->getTotalHits() + 2, $resultSet2->getTotalHits());
}
示例10: searchHtml
/**
*
* @return bool
*/
public function searchHtml()
{
$q = $this->getQuery();
if (!$q) {
echo json_encode(null);
exit;
}
$es = $this->app->container->get('elastica.client');
$search = new Search($es);
$results = $search->search($q);
$hits = [];
foreach ($results->getResults() as $result) {
$result = $result->getHit();
$hits[] = $result['_source'];
}
$this->app->render('partials/searchResutls.html', ['packages' => $hits]);
return true;
}
示例11: searchAction
public function searchAction()
{
//WIP, todo: export to repository and use it in Search Playlists
$elasticaClient = new Client();
$playListIndex = $elasticaClient->getIndex('playlist');
$trackType = $playListIndex->getType('track');
$search = new Search($elasticaClient);
$search->addIndex($playListIndex)->addType($trackType);
$query = new Query();
$query->setSize(5)->setSort(['name' => 'asc'])->setFields(['name', 'ids', 'id', 'composer'])->setExplain(true)->setVersion(true)->setHighlight(['fields' => 'composer']);
$query->setQuery(new MatchAll());
// $query->addAggregation(new \Elastica\Aggregation\Range('name'));
// $term = new \Elastica\Suggest\Term('name', 'field');
// $term->setText('aaaaa');
// $query->setSuggest(new \Elastica\Suggest($term));
// $query->setFacets([new \Elastica\Facet\Range('name')]);
$search->setQuery($query);
$resultSet = $search->search();
$numberOfEntries = $search->count();
$results = $resultSet->getResults();
$totalResults = $resultSet->getTotalHits();
return $this->render('PlayWithElasticSearchBundle:Elastica:search.html.twig', ['query' => $query, 'numberOfEntries' => $numberOfEntries, 'resultSet' => $resultSet, 'results' => $results, 'totalResults' => $totalResults]);
}
示例12: readData
public function readData($source_definition, $rest_parameters = [])
{
Pager::setDefaultLimit(500);
list($limit, $offset) = Pager::calculateLimitAndOffset();
$client = new Client(['host' => $source_definition['host'], 'port' => $source_definition['port'], 'username' => $source_definition['username'], 'password' => $source_definition['password']]);
$index = $client->getIndex($source_definition['es_index']);
$type = $index->getType($source_definition['es_type']);
$search = new Search($client);
$search->addIndex($index);
$search->addType($type);
$query_param = \Input::get('query');
if (empty($query_param)) {
$query = new MatchAll();
$search->setQuery($query);
} else {
$query = new SimpleQueryString($query_param);
$search->setQuery($query);
}
$search->getQuery()->setFrom($offset);
$search->getQuery()->setSize($limit);
$resultSet = $search->search();
$data = new Data();
$data_results = [];
foreach ($resultSet->getResults() as $result) {
$data_result = $result->getData();
unset($data_result['__tdt_etl_timestamp__']);
$data_results[] = $data_result;
}
$data->data = $data_results;
if ($resultSet->getTotalHits() > 0) {
$paging = Pager::calculatePagingHeaders($limit, $offset, $resultSet->getTotalHits());
$data->paging = $paging;
}
$data->preferred_formats = $this->getPreferredFormats();
return $data;
}
示例13: Client
<?php
require_once 'vendor/autoload.php';
use Elastica\Client;
use Elastica\Query;
use Elastica\Query\QueryString;
use Elastica\Search;
$client = new Client();
$index = $client->getIndex('index000');
$type = $index->getType('jdbc');
$search = new Search($client);
$query = new QueryString('クエリー');
$search->setQuery($query);
$resultSet = $search->search();
foreach ($resultSet as $res) {
$d = $res->getData();
print_r($d);
}
?>
示例14: testIgnoreUnavailableOption
/**
* @group functional
*/
public function testIgnoreUnavailableOption()
{
$client = $this->_getClient();
$index = $client->getIndex('elastica_7086b4c2ee585bbb6740ece5ed7ece01');
$query = new MatchAll();
$search = new Search($client);
$search->addIndex($index);
$exception = null;
try {
$search->search($query);
} catch (ResponseException $e) {
$exception = $e;
}
$error = $exception->getResponse()->getFullError();
$this->assertEquals('index_not_found_exception', $error['type']);
$results = $search->search($query, array(Search::OPTION_SEARCH_IGNORE_UNAVAILABLE => true));
$this->assertInstanceOf('\\Elastica\\ResultSet', $results);
}
示例15: findAllWithTracks
public function findAllWithTracks() : array
{
$query = new \Elastica\Query(new \Elastica\Aggregation\Range('playList.name'));
$this->elasticaSearch->setQuery($query);
return $this->buildEntities($this->elasticaSearch->search()->getResults());
}