Ejemplo n.º 1
0
 /**
  * Add a search filter for a specific attribute
  *
  * @param FilterInterface $filter
  *
  * @return $this
  */
 public function addFilter(FilterInterface $filter)
 {
     if ($this->index->isValidAttribute($filter->getName())) {
         $this->filters[$filter->getName()] = $filter;
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Creates the field criteria and validates the supplied field
  *
  * @param string  $field
  * @param integer $within
  * @param boolean $not
  *
  * @return Field
  */
 protected function createField($field, $within, $not = false)
 {
     if (null !== $field && !$this->index->isValidField($field)) {
         $m = 'Specified fields "%s" are not valid for the index "%s"';
         $i = $this->index->getIndexName();
         throw new \InvalidArgumentException(sprintf($m, $field, $i));
     }
     $this->fields[] = $field = new Field($this, $field, $within, $not);
     return $field;
 }
 public function testCanInstantiateWithSettings()
 {
     $index = new SearchIndex('bob', ['field1', 'field2'], ['attr1', 'attr2'], 'MyClass', 'MyClass');
     $this->assertEquals('bob', $index->getIndexName());
     $this->assertEquals('MyClass', $index->getResultSetClass());
     $this->assertEquals('MyClass', $index->getResultClass());
     $this->assertSame(['field1', 'field2'], $index->getAvailableFields());
     $this->assertSame(['attr1', 'attr2'], $index->getAvailableAttributes());
 }