當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。