本文整理汇总了PHP中Elastica\Query::setParam方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setParam方法的具体用法?PHP Query::setParam怎么用?PHP Query::setParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Query
的用法示例。
在下文中一共展示了Query::setParam方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateResults
/**
*
* @param Report $report
* @param number $limit
* @param string $sort
* @param string $order
* @param boolean $lazy
* @param boolean $active
* @param boolean $silent
*
* @return ArrayCollection $data
*/
public function generateResults(Report $report, $limit = 0, $sort = '_score', $order = 'desc', $lazy = true, $active = true, $silent = false)
{
$data = new ArrayCollection();
$request = $this->getServiceLocator()->get('Request');
$silent = $request->getQuery('debug') ? false : $silent;
if ($report instanceof Report) {
$agent = $report->getAgent();
$lead_query = new \Agent\Elastica\Query\BoolQuery();
if ($active) {
$lead_query->addMust(new Elastica\Query\Match('active', 1));
}
$client = $this->getElasticaClient();
if ($agent && $client) {
$filters = $agent->getFilter();
if ($filters) {
$lead_query = $this->applyFilters($lead_query, $filters);
}
$criteria = $agent->getCriteria(false);
if ($criteria) {
try {
$query = new Elastica\Query();
/* @var $criterion \Agent\Entity\AgentCriterion */
foreach ($criteria as $i => $criterion) {
$lead_query = $this->buildQuery($lead_query, $criterion);
}
$query->setQuery($lead_query);
$size = $limit ? $limit : 1000;
$query->setParam('track_scores', true);
$query->addSort([$sort => ['order' => $order]]);
$query->setSize($size);
$results = $this->runQuery($query, $lazy, $silent);
$total = isset($results['total']) ? $results['total'] : false;
if ($total && $results['results']) {
foreach ($results['results'] as $result) {
$data->add($result);
}
}
if ($total > $size) {
$limit = $limit ?: $total;
for ($page = 1; $page < ceil($limit / $size); $page++) {
$query->setFrom($page * $size);
$results = $this->runQuery($query, $silent);
if ($results['results']) {
foreach ($results as $result) {
if (is_array($result)) {
foreach ($result as $r) {
if ($r instanceof Result) {
$data->add($r);
}
}
} elseif ($result instanceof Result) {
$data->add($result);
}
}
}
}
}
} catch (\Exception $e) {
if (!$silent) {
$this->getFlashMessenger()->addErrorMessage($e->getMessage());
}
}
}
}
}
return $data;
}
示例2: search
/**
* Powers full-text-like searches including prefix search.
*
* @param string $type
* @param string $for
* @return Status(mixed) results from the query transformed by the resultsType
*/
private function search($type, $for)
{
if ($this->nonTextQueries) {
$bool = new \Elastica\Query\Bool();
if ($this->query !== null) {
$bool->addMust($this->query);
}
foreach ($this->nonTextQueries as $nonTextQuery) {
$bool->addMust($nonTextQuery);
}
$this->query = $bool;
}
if ($this->resultsType === null) {
$this->resultsType = new FullTextResultsType(FullTextResultsType::HIGHLIGHT_ALL);
}
// Default null queries now so the rest of the method can assume it is not null.
if ($this->query === null) {
$this->query = new \Elastica\Query\MatchAll();
}
$query = new Elastica\Query();
$query->setParam('_source', $this->resultsType->getSourceFiltering());
$query->setParam('fields', $this->resultsType->getFields());
$extraIndexes = array();
$indexType = $this->pickIndexTypeFromNamespaces();
if ($this->namespaces) {
$extraIndexes = $this->getAndFilterExtraIndexes();
if ($this->needNsFilter($extraIndexes, $indexType)) {
$this->filters[] = new \Elastica\Filter\Terms('namespace', $this->namespaces);
}
}
// Wrap $this->query in a filtered query if there are any filters
$unifiedFilter = Filters::unify($this->filters, $this->notFilters);
if ($unifiedFilter !== null) {
$this->query = new \Elastica\Query\Filtered($this->query, $unifiedFilter);
}
// Call installBoosts right after we're done munging the query to include filters
// so any rescores installBoosts adds to the query are done against filtered results.
$this->installBoosts();
$query->setQuery($this->query);
$highlight = $this->resultsType->getHighlightingConfiguration($this->highlightSource);
if ($highlight) {
// Fuzzy queries work _terribly_ with the plain highlighter so just drop any field that is forcing
// the plain highlighter all together. Do this here because this works so badly that no
// ResultsType should be able to use the plain highlighter for these queries.
if ($this->fuzzyQuery) {
$highlight['fields'] = array_filter($highlight['fields'], function ($field) {
return $field['type'] !== 'plain';
});
}
if (!empty($this->nonTextHighlightQueries)) {
// We have some phrase_prefix queries, so let's include them in the
// generated highlight_query.
$bool = new \Elastica\Query\Bool();
if ($this->highlightQuery) {
$bool->addShould($this->highlightQuery);
}
foreach ($this->nonTextHighlightQueries as $nonTextHighlightQuery) {
$bool->addShould($nonTextHighlightQuery);
}
$this->highlightQuery = $bool;
}
if ($this->highlightQuery) {
$highlight['highlight_query'] = $this->highlightQuery->toArray();
}
$query->setHighlight($highlight);
}
if ($this->suggest) {
$query->setParam('suggest', $this->suggest);
$query->addParam('stats', 'suggest');
}
if ($this->offset) {
$query->setFrom($this->offset);
}
if ($this->limit) {
$query->setSize($this->limit);
}
if ($this->sort != 'relevance') {
// Clear rescores if we aren't using relevance as the search sort because they aren't used.
$this->rescore = array();
}
if ($this->rescore) {
// rescore_query has to be in array form before we send it to Elasticsearch but it is way easier to work
// with if we leave it in query for until now
$modifiedRescore = array();
foreach ($this->rescore as $rescore) {
$rescore['query']['rescore_query'] = $rescore['query']['rescore_query']->toArray();
$modifiedRescore[] = $rescore;
}
$query->setParam('rescore', $modifiedRescore);
}
$query->addParam('stats', $type);
switch ($this->sort) {
case 'relevance':
//.........这里部分代码省略.........