コード例 #1
0
ファイル: FacetRange.php プロジェクト: jglaine/sugar761-ent
 /**
  * @see FacetInterface::getFacet
  */
 public function getFacet($fieldName, \Elastica\Filter\AbstractFilter $mainFilter)
 {
     $mainFilter = $this->prepareMainFilter($mainFilter, $fieldName);
     $facet = new \Elastica\Facet\Range($fieldName);
     $facet->setField($fieldName)->setRanges($this->getRangeDefinitions())->setFilter($mainFilter);
     return $facet;
 }
コード例 #2
0
ファイル: Client.php プロジェクト: javik223/Evron-Magento
 /**
  * @param string $q
  * @param array $params
  * @return array
  */
 protected function _getAllFacets($q, array $params)
 {
     $facets = array();
     $hasStats = isset($params['stats']) && isset($params['stats']['fields']) && !empty($params['stats']['fields']);
     if ($hasStats) {
         foreach ($params['stats']['fields'] as $field) {
             $facet = new \Elastica\Facet\Statistical($field);
             $facet->setParam('field', $field);
             $facets[] = $facet;
         }
     }
     if (isset($params['facets']) && !empty($params['facets'])) {
         $properties = $this->_getIndexProperties();
         $filters = isset($params['filters']) ? $params['filters'] : array();
         foreach ($params['facets'] as $field => $conds) {
             $queryFilter = null;
             if (array_key_exists($field, $filters)) {
                 $_params = $params;
                 #AM unset comment out for ATM (Custom Code). Need to test for other clients
                 //  unset($_params['filters'][$field]);
                 $queryFilter = new \Elastica\Filter\Query($this->_getFilteredQuery($q, $_params));
             }
             if (null === $conds) {
                 // Terms Facet
                 if (!$hasStats && array_key_exists($field, $properties)) {
                     $facet = new \Elastica\Facet\Terms($field);
                     if ($properties[$field]['type'] == 'multi_field') {
                         $field .= '.untouched';
                     }
                     $facet->setField($field)->setAllTerms(true)->setSize($this->getFacetsMaxSize());
                     if ($queryFilter) {
                         $facet->setGlobal()->setFilter($queryFilter);
                     }
                     $facets[] = $facet;
                 }
             } elseif (is_array($conds)) {
                 if (isset($conds[0]['from']) && isset($conds[0]['to'])) {
                     if (!$hasStats) {
                         // Range Facet
                         $facet = new \Elastica\Facet\Range($field);
                         $facet->setField($field)->setRanges($this->_helper->_prepareRanges($conds));
                         $facets[] = $facet;
                     }
                 } else {
                     foreach ($conds as $cond) {
                         // Query Facet
                         $query = $this->_helper->_prepareQuery($field, $cond);
                         $facet = new \Elastica\Facet\Query($query);
                         $facet->setQuery(new \Elastica\Query\QueryString($query));
                         if ($queryFilter) {
                             $facet->setGlobal()->setFilter($queryFilter);
                         }
                         $facets[] = $facet;
                     }
                 }
             }
         }
     }
     return $facets;
 }