Пример #1
0
 public function testMoreLikeThisApi()
 {
     $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);
     $type = new Type($index, 'mlt_test');
     $type->addDocument(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')));
     $type->addDocument(new Document(2, array('visible' => true, 'name' => 'bruce wayne')));
     $type->addDocument(new Document(3, array('visible' => false, 'name' => 'bruce wayne')));
     $type->addDocument(new Document(4, array('visible' => true, 'name' => 'batman')));
     $type->addDocument(new Document(5, array('visible' => false, 'name' => 'batman')));
     $type->addDocument(new Document(6, array('visible' => true, 'name' => 'superman')));
     $type->addDocument(new Document(7, array('visible' => true, 'name' => 'spiderman')));
     $index->refresh();
     $document = $type->getDocument(1);
     // Return all similar
     $resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'));
     $this->assertEquals(4, $resultSet->count());
     // Return just the visible similar
     $query = new Query();
     $filterTerm = new Term();
     $filterTerm->setTerm('visible', true);
     $query->setFilter($filterTerm);
     $resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'), $query);
     $this->assertEquals(2, $resultSet->count());
 }