当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::addSort方法代码示例

本文整理汇总了PHP中Elastica\Query::addSort方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::addSort方法的具体用法?PHP Query::addSort怎么用?PHP Query::addSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Query的用法示例。


在下文中一共展示了Query::addSort方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findByUserAndTags

 public function findByUserAndTags(User $user, $tags = null)
 {
     $filterQuery = new Query\Filtered();
     $searchFilter = new Filter\Bool();
     $searchFilter->addMust(new Filter\Term(array('user' => $user->getId())));
     if (!empty($tags)) {
         $tagFilter = new Filter\Terms('tags', explode('+', $tags));
         $tagFilter->setExecution('and');
         $searchFilter->addMust($tagFilter);
     }
     $filterQuery->setFilter($searchFilter);
     $searchQuery = new Query($filterQuery);
     $searchQuery->addSort(array('createdAt' => 'desc'));
     $agg = new Aggregation\Terms('tags');
     $agg->setField('tags')->setOrder('_count', 'desc')->setSize(100);
     $searchQuery->addAggregation($agg);
     return $searchQuery;
 }
开发者ID:emilyemorehouse,项目名称:readlater,代码行数:18,代码来源:BookmarkRepository.php

示例2: testAddSort

 /**
  * @group unit
  */
 public function testAddSort()
 {
     $query = new Query();
     $sortParam = array('firstname' => array('order' => 'asc'));
     $query->addSort($sortParam);
     $this->assertEquals($query->getParam('sort'), array($sortParam));
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:10,代码来源:QueryTest.php

示例3: newQuery

 /**
  * Create a new elastica query from an array of queries.
  *
  * @param array $queries
  * @return Query
  */
 protected function newQuery(array $queries)
 {
     if (!empty($queries)) {
         $container = new BoolQuery();
         foreach ($queries as $query) {
             $container = $this->addQueryToContainer($query, $container);
         }
         $query = new ElasticaQuery($container);
         $query->addSort('_score');
     } else {
         $query = new ElasticaQuery();
     }
     return $query;
 }
开发者ID:amrsoliman,项目名称:laralastica,代码行数:20,代码来源:Laralastica.php

示例4: filteredSearch

 /**
  * Perform a search based on the specified filter
  *
  * @param $typeTerms array
  * @param null $user
  * @param null $sortColumn
  * @param string $sortDirection
  * @param int $limit
  * @return array
  */
 public function filteredSearch($typeTerms, $user = null, $sortColumn = null, $sortDirection = 'desc', $limit = 50)
 {
     $query = new Query();
     $query->setFrom(0);
     $query->setSize($limit);
     $boolQuery = new BoolQuery();
     // Handle 'must' filters
     if (isset($typeTerms['must'])) {
         foreach ($typeTerms['must'] as $type => $term) {
             $termQueryType = new TermQuery([$type => $term]);
             $boolQuery->addMust($termQueryType);
         }
     }
     // Handle 'should' filters
     if (isset($typeTerms['should'])) {
         foreach ($typeTerms['should'] as $type => $term) {
             $termQueryType = new TermQuery([$type => $term]);
             $boolQuery->addShould($termQueryType);
         }
     }
     $query->setQuery($boolQuery);
     if ($user) {
         $userId = $user->id;
         $termQueryUser = new TermQuery(['user_id' => $userId]);
         $boolQuery->addMust($termQueryUser);
     }
     if ($sortColumn) {
         $query->addSort([$sortColumn => ['order' => $sortDirection]]);
     }
     $resultSet = $this->getTypedIndex()->search($query);
     return $this->getModels($resultSet);
 }
开发者ID:brycenrogers,项目名称:linken,代码行数:42,代码来源:SearchHandler.php

示例5: 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;
 }
开发者ID:arstropica,项目名称:zf2-dashboard,代码行数:79,代码来源:ResultAwareTrait.php

示例6: prepareQuery

 /**
  * @return ElasticaQuery
  */
 private function prepareQuery($params, $start = null, $limit = null)
 {
     $query = null;
     $filter = null;
     $sort = ['_score' => 'desc'];
     // We'd like to search in both title and description for keywords
     if (!empty($params['keywords'])) {
         $query = new QueryString($params['keywords']);
         $query->setDefaultOperator('AND')->setFields(['title', 'description']);
     }
     // Add location filter is location is selected from autosuggest
     if (!empty($params['location_id'])) {
         $location = Location::find($params['location_id']);
         $filter = new GeoDistance('location', ['lat' => $location->lat, 'lon' => $location->lon], $params['radius'] . 'mi');
         // Sort by nearest hit
         $sort = ['_geo_distance' => ['jobs.location' => [(double) $location->lon, (double) $location->lat], 'order' => 'asc', 'unit' => 'mi']];
     }
     // If neither keyword nor location supplied, then return all
     if (empty($params['keywords']) && empty($params['location_id'])) {
         $query = new MatchAll();
     }
     // We need a filtered query
     $elasticaQuery = new ElasticaQuery(new Filtered($query, $filter));
     $elasticaQuery->addSort($sort);
     // Offset and limits
     if (!is_null($start) && !is_null($limit)) {
         $elasticaQuery->setFrom($start)->setSize($limit);
     }
     // Set up the highlight
     $elasticaQuery->setHighlight(['order' => 'score', 'fields' => ['title' => ['fragment_size' => 100], 'description' => ['fragment_size' => 200]]]);
     return $elasticaQuery;
 }
开发者ID:phpfour,项目名称:ah,代码行数:35,代码来源:Search.php

示例7: applyESSort

 /**
  * @param Query      $query
  * @param SortConfig $sortConfig
  */
 protected function applyESSort(Query $query, SortConfig $sortConfig)
 {
     $column = $sortConfig->getColumn();
     if ($column) {
         $direction = $sortConfig->getDirection() ? 'desc' : 'asc';
         // null or false both default to ASC
         $query->addSort([$column => ['order' => $direction]]);
     }
 }
开发者ID:VincentChalnot,项目名称:SidusEAVFilterBundle,代码行数:13,代码来源:EAVElasticaFilterConfigurationHandler.php


注:本文中的Elastica\Query::addSort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。