Ejemplo n.º 1
0
	public function testFilteredSearch() {
		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('helloworld');

		$doc = new Elastica_Document(1, array('name' => 'hello world'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(2, array('name' => 'nicolas ruflin'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(3, array('name' => 'ruflin'));
		$type->addDocument($doc);


		$query = new Elastica_Query_Terms();
		$query->setTerms('name', array('nicolas', 'hello'));

		$index->refresh();

		$resultSet = $type->search($query);

		$this->assertEquals(2, $resultSet->count());

		$query->addTerm('ruflin');
		$resultSet = $type->search($query);

		$this->assertEquals(3, $resultSet->count());
	}
Ejemplo n.º 2
0
 public function testShouldReturnTheRightNumberOfResult()
 {
     $f = new Elastica_Filter_Nested();
     $this->assertEquals(array('nested' => array()), $f->toArray());
     $q = new Elastica_Query_Terms();
     $q->setTerms('hobby', array('guitar'));
     $f->setPath('hobbies');
     $f->setQuery($q);
     $c = new Elastica_Client();
     $s = new Elastica_Search($c);
     $i = $c->getIndex('elastica_test_filter_nested');
     $s->addIndex($i);
     $r = $s->search($f);
     $this->assertEquals(1, $r->getTotalHits());
     $f = new Elastica_Filter_Nested();
     $this->assertEquals(array('nested' => array()), $f->toArray());
     $q = new Elastica_Query_Terms();
     $q->setTerms('hobby', array('opensource'));
     $f->setPath('hobbies');
     $f->setQuery($q);
     $c = new Elastica_Client();
     $s = new Elastica_Search($c);
     $i = $c->getIndex('elastica_test_filter_nested');
     $s->addIndex($i);
     $r = $s->search($f);
     $this->assertEquals(2, $r->getTotalHits());
 }