Beispiel #1
0
 public function testConfigMode()
 {
     $options = array('facet' => array(array('type' => 'query', 'key' => 'f1', 'query' => 'category:1'), 'f2' => array('type' => 'query', 'query' => 'category:2')), 'prefix' => 'pr', 'sort' => 'index', 'mincount' => 10, 'missing' => 5, 'extractfromresponse' => true, 'contains' => 'foobar', 'containsignorecase' => true);
     $this->facetSet->setOptions($options);
     $facets = $this->facetSet->getFacets();
     $this->assertEquals(2, count($facets));
     $this->assertEquals($options['prefix'], $this->facetSet->getPrefix());
     $this->assertEquals($options['sort'], $this->facetSet->getSort());
     $this->assertEquals($options['mincount'], $this->facetSet->getMincount());
     $this->assertEquals($options['missing'], $this->facetSet->getMissing());
     $this->assertEquals($options['extractfromresponse'], $this->facetSet->getExtractFromResponse());
     $this->assertEquals($options['contains'], $this->facetSet->getContains());
     $this->assertEquals($options['containsignorecase'], $this->facetSet->getContainsIgnoreCase());
 }
Beispiel #2
0
 /**
  * Add request settings for FacetSet.
  *
  * @throws UnexpectedValueException
  *
  * @param FacetsetComponent $component
  * @param Request           $request
  *
  * @return Request
  */
 public function buildComponent($component, $request)
 {
     $facets = $component->getFacets();
     if (count($facets) !== 0) {
         // enable faceting
         $request->addParam('facet', 'true');
         // global facet params
         $request->addParam('facet.sort', $component->getSort());
         $request->addParam('facet.prefix', $component->getPrefix());
         $request->addParam('facet.contains', $component->getContains());
         $request->addParam('facet.contains.ignoreCase', is_null($ignoreCase = $component->getContainsIgnoreCase()) ? null : ($ignoreCase ? 'true' : 'false'));
         $request->addParam('facet.missing', $component->getMissing());
         $request->addParam('facet.mincount', $component->getMinCount());
         $request->addParam('facet.limit', $component->getLimit());
         foreach ($facets as $facet) {
             switch ($facet->getType()) {
                 case FacetsetComponent::FACET_FIELD:
                     $this->addFacetField($request, $facet);
                     break;
                 case FacetsetComponent::FACET_QUERY:
                     $this->addFacetQuery($request, $facet);
                     break;
                 case FacetsetComponent::FACET_MULTIQUERY:
                     $this->addFacetMultiQuery($request, $facet);
                     break;
                 case FacetsetComponent::FACET_RANGE:
                     $this->addFacetRange($request, $facet);
                     break;
                 case FacetsetComponent::FACET_PIVOT:
                     $this->addFacetPivot($request, $facet);
                     break;
                 case FacetsetComponent::FACET_INTERVAL:
                     $this->addFacetInterval($request, $facet);
                     break;
                 default:
                     throw new UnexpectedValueException('Unknown facet type');
             }
         }
     }
     return $request;
 }