예제 #1
0
파일: TypeTest.php 프로젝트: ro-ka/Elastica
	public function testMoreLikeThisApi() {

		$client = new Elastica_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 Elastica_Type($index, 'mlt_test');
		$type->addDocument(new Elastica_Document(1, array('visible' => true, 'name' => 'bruce wayne batman')));
		$type->addDocument(new Elastica_Document(2, array('visible' => true, 'name' => 'bruce wayne')));
		$type->addDocument(new Elastica_Document(3, array('visible' => false, 'name' => 'bruce wayne')));
		$type->addDocument(new Elastica_Document(4, array('visible' => true, 'name' => 'batman')));
		$type->addDocument(new Elastica_Document(5, array('visible' => false, 'name' => 'batman')));
		$type->addDocument(new Elastica_Document(6, array('visible' => true, 'name' => 'superman')));
		$type->addDocument(new Elastica_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 Elastica_Query();
		$filterTerm 		= new Elastica_Filter_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());
	}
예제 #2
0
 public function testGetDocumentNotExist()
 {
     $index = $this->_createIndex();
     $type = new Elastica_Type($index, 'test');
     $type->addDocument(new Elastica_Document(1, array('name' => 'ruflin')));
     $index->refresh();
     $type->getDocument(1);
     try {
         $type->getDocument(2);
         $this->fail('Should throw exceptoin as doc does not exist');
     } catch (Elastica_Exception_NotFound $e) {
         $this->assertTrue(true);
     }
 }