public function testMatchDoc() { $client = new Client(array('persistent' => false)); $index = $client->getIndex('elastica_test'); $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true); $percolator = new Percolator($index); $percolatorName = 'percotest'; $query = new Term(array('name' => 'ruflin')); $response = $percolator->registerQuery($percolatorName, $query); $this->assertTrue($response->isOk()); $this->assertFalse($response->hasError()); $doc1 = new Document(); $doc1->set('name', 'ruflin'); $doc2 = new Document(); $doc2->set('name', 'nicolas'); $index = new Index($index->getClient(), '_percolator'); $index->optimize(); $index->refresh(); $matches1 = $percolator->matchDoc($doc1); $this->assertTrue(in_array($percolatorName, $matches1)); $this->assertEquals(1, count($matches1)); $matches2 = $percolator->matchDoc($doc2); $this->assertEmpty($matches2); }
protected function _getDefaultPercolator($percolatorName = 'existingDoc') { $index = $this->_createIndex(); $percolator = new Percolator($index); $query = new Term(array('name' => 'foobar')); $percolator->registerQuery($percolatorName, $query); return $percolator; }
/** * @group functional */ public function testPercolateWithAdditionalRequestBodyOptions() { $index = $this->_createIndex(); $percolator = new Percolator($index); $query = new Term(array('name' => 'foo')); $response = $percolator->registerQuery('percotest', $query, array('field1' => array('tag1', 'tag2'))); $this->assertTrue($response->isOk()); $this->assertFalse($response->hasError()); $query = new Term(array('name' => 'foo')); $response = $percolator->registerQuery('percotest1', $query, array('field1' => array('tag2'))); $this->assertTrue($response->isOk()); $this->assertFalse($response->hasError()); $doc1 = new Document(); $doc1->set('name', 'foo'); $index->refresh(); $options = array('track_scores' => true, 'sort' => array('_score' => 'desc'), 'size' => 1); $matches = $percolator->matchDoc($doc1, new Term(array('field1' => 'tag2')), 'type', $options); $this->assertCount(1, $matches); $this->assertEquals('percotest1', $matches[0]['_id']); $this->assertArrayHasKey('_score', $matches[0]); }