本文整理汇总了PHP中Elastica\Query::setSort方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setSort方法的具体用法?PHP Query::setSort怎么用?PHP Query::setSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Query
的用法示例。
在下文中一共展示了Query::setSort方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addSortingToQuery
/**
* @param \Elastica\Query $query
* @param \Spryker\Client\Search\Dependency\Plugin\SortConfigBuilderInterface $sortConfig
* @param array $requestParameters
*
* @return void
*/
protected function addSortingToQuery(Query $query, SortConfigBuilderInterface $sortConfig, array $requestParameters)
{
$sortParamName = $sortConfig->getActiveParamName($requestParameters);
$sortConfigTransfer = $sortConfig->get($sortParamName);
if ($sortConfigTransfer === null) {
return;
}
$nestedSortField = $sortConfigTransfer->getFieldName() . '.' . $sortConfigTransfer->getName();
$query->setSort([$nestedSortField => ['order' => $sortConfig->getSortDirection($sortParamName), 'mode' => 'min']]);
}
示例2: findPaginatedByQueryAndCategory
/**
* @inheritdoc
*/
public function findPaginatedByQueryAndCategory(\string $queryString = null, \string $category = null, \int $priceFrom = null, \int $priceTo = null, \bool $availability = null)
{
$queryObject = new Query();
$filter = new BoolAnd();
if ($queryString) {
$query = new Match('_all', ['query' => $queryString, 'operator' => 'AND']);
} else {
$query = new Query\MatchAll();
}
if ($availability !== null) {
$filter->addFilter(new Term(['availability' => $availability]));
}
$range = [];
if ($priceFrom) {
$range['gte'] = $priceFrom;
}
if ($priceTo) {
$range['lte'] = $priceTo;
}
if ($range) {
$filter->addFilter(new Range('price', $range));
}
if ($category) {
$term = new Term(['category.id' => $category]);
$queryObject->setPostFilter($term);
}
$terms = new Terms('categories');
$terms->setField('category.id');
$terms->setSize(0);
$queryObject->addAggregation($terms);
if ($filter->getFilters()) {
$filtered = new Query\Filtered($query, $filter);
$queryObject->setQuery($filtered);
} else {
$queryObject->setQuery($query);
}
$queryObject->setSort(['updated' => 'desc']);
$queryObject->setMinScore(0.5);
return $this->findPaginated($queryObject);
}
示例3: searchText
/**
* @param string $term text to search
* @return \Status
*/
public function searchText($term)
{
$term = trim($term);
// No searching for nothing! That takes forever!
if (!$term) {
return null;
}
$query = new Query();
$offset = min($this->offset, static::MAX_OFFSET);
if ($offset) {
$query->setFrom($offset);
}
if ($this->limit) {
$query->setSize($this->limit);
}
$filter = new Bool();
// filters
if ($this->namespaces) {
$filter->addMust(new Terms('namespace', $this->namespaces));
}
if ($this->pageIds) {
$filter->addMust(new Terms('pageid', $this->pageIds));
}
if ($this->moderationStates) {
$filter->addMust(new Terms('revisions.moderation_state', $this->moderationStates));
}
// only apply filters if there are any
if ($filter->toArray()) {
$query->setFilter($filter);
}
$sortArgs = $this->getSortArgs();
if (isset($sortArgs[$this->sort]) && $sortArgs[$this->sort]) {
$query->setSort($sortArgs[$this->sort]);
}
// @todo: interwiki stuff? (see \CirrusSearch)
$searcher = new Searcher($query, false, $this->type);
return $searcher->searchText($term);
}
示例4: search
//.........这里部分代码省略.........
$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':
break;
// The default
// The default
case 'title_asc':
$query->setSort(array('title.keyword' => 'asc'));
break;
case 'title_desc':
$query->setSort(array('title.keyword' => 'desc'));
break;
case 'incoming_links_asc':
$query->setSort(array('incoming_links' => array('order' => 'asc', 'missing' => '_first')));
break;
case 'incoming_links_desc':
$query->setSort(array('incoming_links' => array('order' => 'desc', 'missing' => '_last')));
break;
default:
LoggerFactory::getInstance('CirrusSearch')->warning("Invalid sort type: {sort}", array('sort' => $this->sort));
}
$queryOptions = array();
if ($this->config->get('CirrusSearchMoreAccurateScoringMode')) {
$queryOptions['search_type'] = 'dfs_query_then_fetch';
}
switch ($type) {
case 'regex':
$poolCounterType = 'CirrusSearch-Regex';
$queryOptions['timeout'] = $this->config->getElement('CirrusSearchSearchShardTimeout', 'regex');
break;
case 'prefix':
$poolCounterType = 'CirrusSearch-Prefix';
$queryOptions['timeout'] = $this->config->getElement('CirrusSearchSearchShardTimeout', 'default');
break;
default:
$poolCounterType = 'CirrusSearch-Search';
$queryOptions['timeout'] = $this->config->getElement('CirrusSearchSearchShardTimeout', 'default');
}
$this->connection->setTimeout($queryOptions['timeout']);
// Setup the search
示例5: searchChildren
/**
* Search children.
*
* @param string $type Post type
* @param int $parent Parent ID to get all children
* @param string $order Order way
* @return array $search Combine of all results, total and aggregations
*
* @since 3.0.0
*/
public function searchChildren($type, $parent, $order = 'desc')
{
//Check page
if (is_search()) {
return;
}
//Return array
$return = array('parent' => $parent, 'total' => 0, 'results' => array());
//Check request
if (empty($parent)) {
return $return;
}
//Get query vars
$results = array();
$types = array();
//Get Elasticsearch datas
$index = $this->getIndex();
//Check index
if (null === $index || empty($index)) {
return $return;
}
//Create the actual search object with some data.
$es_query = new Query();
//Define term
$es_term = new Term();
$es_term->setTerm($type . '.parent', $parent);
//Filter 'And'
$es_filter = new Bool();
$es_filter->addMust($es_term);
//Add filter to the search object
$es_query->setFilter($es_filter);
//Add sort
$es_query->setSort(array($type . '.date' => array('order' => $order)));
//Search!
$es_resultset = $index->search($es_query);
//Retrieve data
$es_results = $es_resultset->getResults();
//Check results
if (null == $es_results || empty($es_results)) {
return $return;
}
//Iterate to retrieve all IDs
foreach ($es_results as $res) {
$typ = $res->getType();
//Save type
$types[$typ] = $typ;
//Save datas
$results[$typ][] = array('id' => $res->getId(), 'score' => $res->getScore(), 'source' => $res->getSource());
}
//Get total
$total = $es_resultset->getTotalHits();
//Return everything
$return = array('parent' => $parent, 'total' => $total, 'results' => $results);
return $return;
}
示例6: termQuery
/**
* @param string $term
* @param string $value
* @param int $size
*
* @return \Elastica\ResultSet
*/
public function termQuery($term, $value, $size = 30)
{
$_agg = new Aggregation();
$_facet = $_agg->date_histogram('occurred_on', '@timestamp', ElkIntervals::DAY);
// $_facet = new DateHistogram('occurred_on');
// $_facet->setField('@timestamp');
// $_facet->setInterval('day');
$_query = new Query();
$_query->setSize($size);
$_query->setSort(['@timestamp']);
// Filter for term
$_filter = new Prefix($term, $value);
$_and = new Bool();
$_and->addMust($_filter);
$_query->setPostFilter($_and);
$_query->addAggregation($_facet);
$_results = $this->_doSearch($_query);
return $_results;
}
示例7: generateQueryBy
/**
* {@inheritdoc}
*/
public function generateQueryBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
$query = new Query();
if (empty($criteria)) {
$query->setQuery(new MatchAll());
} else {
$query->setQuery(new Filtered(null, $this->generateFilterBy($criteria)));
}
if ($orderBy) {
$query->setSort($orderBy);
}
if ($limit) {
$query->setSize($limit);
}
if ($offset) {
$query->setFrom($offset);
}
return $query;
}
示例8: publisherAction
public function publisherAction(Request $request, $page = 1)
{
$getTypes = $request->query->get('type_filters');
$typeFilters = !empty($getTypes) ? explode(',', $getTypes) : [];
$publisherSearcher = $this->get('fos_elastica.index.search.publisher');
$boolQuery = new Query\BoolQuery();
if (!empty($typeFilters)) {
foreach ($typeFilters as $type) {
$match = new Query\Match();
$match->setField('publisherType', $type);
$boolQuery->addMust($match);
}
}
$publisherQuery = new Query($boolQuery);
$publisherQuery->setSort(['name.raw' => ['order' => 'asc']]);
$typeAgg = new Aggregation\Terms('types');
$typeAgg->setField('publisher.publisherType.name');
$typeAgg->setOrder('_term', 'asc');
$typeAgg->setSize(0);
$publisherQuery->addAggregation($typeAgg);
$adapter = new ElasticaAdapter($publisherSearcher, $publisherQuery);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(20);
$pagerfanta->setCurrentPage($page);
$publishers = $pagerfanta->getCurrentPageResults();
$types = $adapter->getResultSet()->getAggregation('types')['buckets'];
$data = ['types' => $types, 'page' => 'ojs_site_explore_publisher', 'publishers' => $publishers, 'pagerfanta' => $pagerfanta, 'type_filters' => $typeFilters];
return $this->render('OjsSiteBundle:Explore:publisher.html.twig', $data);
}
示例9: sortBy
public function sortBy($sort)
{
$query = new \Elastica\Query('agg_name');
$query->setSort($sort);
$this->query[] = $query;
return $query;
}