Esempio n. 1
0
 /**
  * Tests that parent fields are not overwritten by the toArray method.
  *
  * @group unit
  */
 public function testSetCachedNotOverwritten()
 {
     $filter = new Range('field_name', array());
     $filter->setCached(true);
     $array = $filter->toArray();
     $this->assertTrue($array['range']['_cache']);
 }
 public function testToArray()
 {
     $filter = new Range();
     $fromTo = array('from' => 'ra', 'to' => 'ru');
     $filter->addField('name', $fromTo);
     $expectedArray = array('range' => array('name' => $fromTo));
     $this->assertEquals($expectedArray, $filter->toArray());
 }
Esempio n. 3
0
 /**
  * @param $appliedFilters
  * @param $elasticaQuery
  *
  * @return array
  */
 public function applyFilterToElasticaQuery($appliedFilters, $elasticaQuery)
 {
     $rangeFilters = new BoolOr();
     $boolFilter = new BoolFilter();
     $filters = [];
     $termFilters = [];
     foreach ($appliedFilters as $facet) {
         if (strpos($facet[key($facet)], '|') !== false) {
             $filters[key($facet)][] = ['range' => explode('|', $facet[key($facet)])];
         } else {
             $filters[key($facet)][] = $facet[key($facet)];
         }
     }
     foreach ($filters as $name => $value) {
         if (is_array($value[0])) {
             foreach ($value as $range) {
                 $rangeFilter = new FilterRange();
                 $rangeFilter->addField($name, ['gte' => $range['range'][0], 'lte' => $range['range'][1]]);
                 $rangeFilters->addFilter($rangeFilter);
             }
             $boolFilter->addShould($rangeFilters);
         } else {
             $termFilters = new FilterTerms();
             $termFilters->setTerms($name, $value);
             $boolFilter->addShould($termFilters);
         }
     }
     $elasticaQuery->setFilter($boolFilter);
     return [$termFilters, $rangeFilters, $boolFilter, $filters];
 }