Exemple #1
0
 public function testSetAndGetQueryWithBind()
 {
     $this->facet->setQuery('id:%1%', array(678));
     $this->assertEquals('id:678', $this->facet->getQuery());
 }
 /**
  * Add a facet result for a facet query
  *
  * @param  QueryFacetQuery  $facet
  * @param  array            $data
  * @return ResultFacetQuery
  */
 protected function facetQuery($facet, $data)
 {
     $key = $facet->getKey();
     if (isset($data['facet_counts']['facet_queries'][$key])) {
         $value = $data['facet_counts']['facet_queries'][$key];
         return new ResultFacetQuery($value);
     }
 }
Exemple #3
0
 /**
  * Add params for a facet query to request
  *
  * @param  Request    $request
  * @param  FacetQuery $facet
  * @return void
  */
 public function addFacetQuery($request, $facet)
 {
     $request->addParam('facet.query', $this->renderLocalParams($facet->getQuery(), array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())));
 }
Exemple #4
0
 public function testSetFacets()
 {
     $fq1 = new FacetQuery();
     $fq1->setKey('f1')->setQuery('category:1');
     $fq2 = new FacetQuery();
     $fq2->setKey('f2')->setQuery('category:2');
     $facets = array('f1' => $fq1, 'f2' => $fq2);
     $this->facetSet->addFacets($facets);
     $fq3 = new FacetQuery();
     $fq3->setKey('f3')->setQuery('category:3');
     $fq4 = new FacetQuery();
     $fq4->setKey('f4')->setQuery('category:4');
     $facets = array('f3' => $fq3, 'f4' => $fq4);
     $this->facetSet->setFacets($facets);
     $this->assertEquals($facets, $this->facetSet->getFacets());
 }
 public function testClearExcludesForwarding()
 {
     $this->facet->addExclude('fq1');
     $this->facet->addExclude('fq2');
     $facetQuery = new Query();
     $facetQuery->setKey('k1');
     $facetQuery->setQuery('category:1');
     $this->facet->addQuery($facetQuery);
     $this->assertEquals(array('fq1', 'fq2'), $facetQuery->getExcludes());
     $this->facet->clearExcludes();
     $this->assertEquals(array(), $facetQuery->getExcludes());
 }
Exemple #6
0
 /**
  * Add a facet result for a facet query
  *
  * @param  QueryFacetQuery       $facet
  * @param  array                 $data
  * @return ResultFacetQuery|null
  */
 protected function facetQuery($facet, $data)
 {
     $key = $facet->getKey();
     if (!isset($data['facet_counts']['facet_queries'][$key])) {
         return null;
     }
     return new ResultFacetQuery($data['facet_counts']['facet_queries'][$key]);
 }
Exemple #7
0
 /**
  * Add a facetquery
  *
  * Supports a facetquery instance or a config array, in that case a new
  * facetquery instance wil be created based on the options.
  *
  * @throws InvalidArgumentException
  * @param  Query|array              $facetQuery
  * @return self                     Provides fluent interface
  */
 public function addQuery($facetQuery)
 {
     if (is_array($facetQuery)) {
         $facetQuery = new Query($facetQuery);
     }
     $key = $facetQuery->getKey();
     if (0 === strlen($key)) {
         throw new InvalidArgumentException('A facetquery must have a key value');
     }
     if (array_key_exists($key, $this->facetQueries)) {
         throw new InvalidArgumentException('A query must have a unique key value within a multiquery facet');
     }
     // forward shared excludes
     $facetQuery->addExcludes($this->getExcludes());
     $this->facetQueries[$key] = $facetQuery;
     return $this;
 }