public function testSearch() { $client = new Elastica_Client(); $index = new Elastica_Index($client, 'test'); $index->create(array(), true); $index->getSettings()->setNumberOfReplicas(0); //$index->getSettings()->setNumberOfShards(1); $type = new Elastica_Type($index, 'helloworldfuzzy'); $mapping = new Elastica_Type_Mapping($type , array( 'email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), )); $mapping->setSource(array('enabled' => false)); $type->setMapping($mapping); $doc = new Elastica_Document(1000, array('email' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!')); $type->addDocument($doc); // Refresh index $index->refresh(); $fltQuery = new Elastica_Query_FuzzyLikeThis(); $fltQuery->setLikeText("sample gmail"); $fltQuery->addFields(array("email","content")); $fltQuery->setMinSimilarity(0.3); $fltQuery->setMaxQueryTerms(3); $resultSet = $type->search($fltQuery); $this->assertEquals(1, $resultSet->count()); }
public function testSearch() { $client = new Elastica_Client(); $index = new Elastica_Index($client, 'test'); $index->create(array(), true); $index->getSettings()->setNumberOfReplicas(0); //$index->getSettings()->setNumberOfShards(1); $type = new Elastica_Type($index, 'helloworldmlt'); $mapping = new Elastica_Type_Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'))); $mapping->setSource(array('enabled' => false)); $type->setMapping($mapping); $doc = new Elastica_Document(1000, array('email' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!')); $type->addDocument($doc); $doc = new Elastica_Document(1001, array('email' => '*****@*****.**', 'content' => 'This is a fake nospam email address for gmail')); $type->addDocument($doc); // Refresh index $index->refresh(); $mltQuery = new Elastica_Query_MoreLikeThis(); $mltQuery->setLikeText('fake gmail sample'); $mltQuery->setFields(array('email', 'content')); $mltQuery->setMaxQueryTerms(1); $mltQuery->setMinDocFrequency(1); $mltQuery->setMinTermFrequency(1); $query = new Elastica_Query(); $query->setFields(array('email', 'content')); $query->setQuery($mltQuery); $resultSet = $type->search($query); $resultSet->getResponse()->getData(); $this->assertEquals(2, $resultSet->count()); }
public function testSearch() { $client = new Elastica_Client(); $index = new Elastica_Index($client, 'test'); $index->create(array(), true); $index->getSettings()->setNumberOfReplicas(0); //$index->getSettings()->setNumberOfShards(1); $type = new Elastica_Type($index, 'helloworld'); $doc = new Elastica_Document(1, array('email' => '*****@*****.**', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))); $type->addDocument($doc); // Refresh index $index->refresh(); $queryString = new Elastica_Query_QueryString('test*'); $resultSet = $type->search($queryString); $this->assertEquals(1, $resultSet->count()); }
public function testSetReadOnly() { $client = new Elastica_Client(); $index = new Elastica_Index($client, 'elastica_test'); $index->getSettings()->setReadOnly(false); $index = $this->_createIndex(); // Add document to normal index $doc = new Elastica_Document(null, array('hello' => 'world')); $type = $index->getType('test'); $type->addDocument($doc); $this->assertFalse((bool) $index->getSettings()->get('blocks.read_only')); // Try to add doc to read only index $index->getSettings()->setReadOnly(true); $this->assertTrue((bool) $index->getSettings()->get('blocks.read_only')); try { $type->addDocument($doc); $this->fail('Should throw exception because of read only'); } catch(Elastica_Exception_Response $e) { $message = $e->getMessage(); $this->assertContains('ClusterBlockException', $message); $this->assertContains('index read-only', $message); } // Remove read only, add document $response = $index->getSettings()->setReadOnly(false); $this->assertTrue($response->isOk()); $type->addDocument($doc); $index->refresh(); $this->assertEquals(2, $type->count()); }