本文整理汇总了PHP中Elastica\Search::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::getQuery方法的具体用法?PHP Search::getQuery怎么用?PHP Search::getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Search
的用法示例。
在下文中一共展示了Search::getQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例4: buildResultSet
/**
* @param Response $childResponse
* @param BaseSearch $search
*
* @return \Elastica\ResultSet
*/
private function buildResultSet(Response $childResponse, BaseSearch $search)
{
return $search->getResultSetBuilder()->buildResultSet($childResponse, $search->getQuery());
}
示例5: buildCount
/**
* Build a Search that will count all pages that link to $titles.
* @param string $titles title in prefixedDBKey form
* @return Search that counts all pages that link to $titles
*/
private function buildCount($titles)
{
$filter = new Terms('outgoing_link', $titles);
$filter->setCached(false);
// We're not going to be redoing this any time soon.
$type = $this->connection->getPageType(wfWikiId());
$search = new Search($type->getIndex()->getClient());
$search->addIndex($type->getIndex());
$search->addType($type);
$search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_COUNT);
$matchAll = new MatchAll();
$search->setQuery(new Filtered($matchAll, $filter));
$search->getQuery()->addParam('stats', 'link_count');
return $search;
}
示例6: _prepareSearch
/**
* index: 11 docs
* query size: 5.
*
* @return Search
*/
private function _prepareSearch()
{
$index = $this->_createIndex();
$index->refresh();
$docs = array();
for ($x = 1; $x <= 11; $x++) {
$docs[] = new Document($x, array('id' => $x, 'key' => 'value'));
}
$type = $index->getType('scrollTest');
$type->addDocuments($docs);
$index->refresh();
$search = new Search($this->_getClient());
$search->addIndex($index)->addType($type);
$search->getQuery()->setSize(5);
return $search;
}