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


PHP Query::setParams方法代码示例

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


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

示例1: getResults

 /**
  * @param array $params
  *
  * @return array
  */
 public function getResults(array $params)
 {
     $locale = $this->context->get('language');
     $brand = $this->context->get('brand');
     $brands = array_keys($this->context->getValues('brand'));
     $results = array();
     $params = array_merge(array('term' => '', 'method' => 'lieu'), $params);
     if ('lieu' == ($method = $params['method'])) {
         $params['term'] = '';
     }
     $term = $params['term'];
     $localizedNameField = sprintf('names.%s', $locale);
     if (!in_array($method, array('lieu', 'location'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('term' => array('brandSlug' => $queryBrand));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array('name' => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array('name' => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $hotels = $this->hotelType->search($query);
         /** @var Result $hotel */
         foreach ($hotels as $hotel) {
             $hotel = $hotel->getSource();
             if ($hotel['active']) {
                 $result = array('brand' => $hotel['brandName'], 'brandId' => strtolower($hotel['brandSlug']), 'label' => (isset($params['hotel_name_brand']) and $params['hotel_name_brand']) ? sprintf('%s %s', $hotel['brandName'], $hotel['name']) : $hotel['name'], 'typeResult' => 'hotel', 'id' => $hotel['id'], 'activeLocationId' => $hotel['cityId'], 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.hotels'), 'cssClass' => 'lvl1', 'latLng' => $hotel['latLng']);
                 if ($method == 'lieu') {
                     $result['type'] = 'lieu';
                 }
                 $results[] = $result;
             }
         }
     }
     if (!in_array($method, array('lieu', 'hotel'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $cities = $this->cityType->search($query);
         /** @var Result $city */
         foreach ($cities as $city) {
             $city = $city->getSource();
             $results[] = array('label' => $city['names'][$locale], 'typeResult' => 'city', 'id' => $city['id'], 'activeLocationId' => sprintf('city%s', $city['id']), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.cities'), 'cssClass' => 'lvl1');
         }
     }
     if (!in_array($method, array('hotel', 'location'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $departments = $this->departmentType->search($query);
         /** @var Result $department */
         foreach ($departments as $department) {
             $department = $department->getSource();
             $cityIds = $department['citiesIds'];
             $cityIds = array_map(function ($cityId) {
                 return sprintf('city%s', $cityId);
             }, $cityIds);
             $result = array('label' => $department['names'][$locale], 'typeResult' => 'department', 'id' => $department['id'], 'activeLocationId' => implode(',', $cityIds), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.departments'), 'cssClass' => 'lvl1');
             if ($method == 'lieu') {
                 $result['type'] = 'lieu';
                 $result['cssClass'] = 'lvl3';
             }
             $results[] = $result;
         }
     }
     if (!in_array($method, array('hotel'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
//.........这里部分代码省略.........
开发者ID:blab2015,项目名称:seh,代码行数:101,代码来源:AutocompleteManager.php


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