Ejemplo n.º 1
0
	public function testTextPhrase() {

		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('test');

		$doc = new Elastica_Document(1, array('name' => 'Basel-Stadt'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(2, array('name' => 'New York'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(3, array('name' => 'New Hampshire'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(4, array('name' => 'Basel Land'));
		$type->addDocument($doc);


		$index->refresh();

		$type = 'text_phrase';
		$field = 'name';

		$query = new Elastica_Query_Text();
		$query->setFieldQuery($field, 'Basel New');
		$query->setField('operator', 'OR');
		$query->setFieldType($field, $type);

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

		$this->assertEquals(4, $resultSet->count());
	}
Ejemplo n.º 2
0
	public function testSetCache() {

		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('test');

		$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);


		$and = new Elastica_Filter_And();

		$idsFilter1 = new Elastica_Filter_Ids();
		$idsFilter1->setIds(1);

		$idsFilter2 = new Elastica_Filter_Ids();
		$idsFilter2->setIds(1);

		$and->addFilter($idsFilter1);
		$and->addFilter($idsFilter2);

		$index->refresh();
		$and->setCached(true);



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

		$this->assertEquals(1, $resultSet->count());
	}
Ejemplo n.º 3
0
 public function testGeoPoint()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('point' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Elastica_Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Elastica_Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('point', 30, 40);
     $type->addDocument($doc2);
     $index->optimize();
     $index->refresh();
     // Only one point should be in radius
     $query = new Elastica_Query();
     $geoFilter = new Elastica_Filter_GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
     $query = new Elastica_Query(new Elastica_Query_MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Elastica_Query();
     $geoFilter = new Elastica_Filter_GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
     $query = new Elastica_Query(new Elastica_Query_MatchAll());
     $query->setFilter($geoFilter);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
Ejemplo n.º 4
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());
 }
Ejemplo n.º 5
0
	public function testExample() {
		// Creates a new index 'xodoa' and a type 'user' inside this index
		$client = new Elastica_Client();
		$index = $client->getIndex('elastica_test');
		$index->create(array(), true);

		$type = $index->getType('user');

		// Adds 1 document to the index
		$doc1 = new Elastica_Document(1,
			array('username' => 'hans', 'test' => array('2', '3', '5'))
		);
		$type->addDocument($doc1);

		// Adds a list of documents with _bulk upload to the index
		$docs = array();
		$docs[] = new Elastica_Document(2,
			array('username' => 'john', 'test' => array('1', '3', '6'))
		);
		$docs[] = new Elastica_Document(3,
			array('username' => 'rolf', 'test' => array('2', '3', '7'))
		);
		$type->addDocuments($docs);

		// Refresh index
		$index->refresh();

		$resultSet = $type->search('rolf');
	}
Ejemplo n.º 6
0
	/**
	 * Some memory usage stats
	 * 
	 * Really simple and quite stupid ...
	 */
	public function testServersArray() {

		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('test');

		$data = array(
			'text1' => 'Very long text for a string',
			'text2' => 'But this is not very long',
			'text3' => 'random or not random?',
		);
		
		$startMemory = memory_get_usage();
		
		for ($n = 1; $n < 10; $n++) {
			$docs = array();
			
			for ($i = 1; $i <= 3000; $i++) {
				$docs[] = new Elastica_Document(uniqid(), $data);
			}			
	
			$type->addDocuments($docs);
			$docs = array();			
		}
		
		unset($docs);
		
		$endMemory = memory_get_usage();
		
		$this->assertLessThan(1.1, $endMemory/$startMemory);
	}
Ejemplo n.º 7
0
	public function testStatisticalWithSetFields() {
		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('helloworld');

		$doc = new Elastica_Document(1, array('price' => 10, 'price2' => 20));
		$type->addDocument($doc);
		$doc = new Elastica_Document(2, array('price' => 35, 'price2' => 70));
		$type->addDocument($doc);
		$doc = new Elastica_Document(2, array('price' => 45, 'price2' => 90));
		$type->addDocument($doc);

		$facet = new Elastica_Facet_Statistical('stats');
		$facet->setFields(array('price','price2'));

		$query = new Elastica_Query();
		$query->addFacet($facet);
		$query->setQuery(new Elastica_Query_MatchAll());

		$index->refresh();

		$response = $type->search($query);
		$facets = $response->getFacets();

		$this->assertEquals(165, $facets['stats']['total']);
		$this->assertEquals(10, $facets['stats']['min']);
		$this->assertEquals(90, $facets['stats']['max']);
	}
Ejemplo n.º 8
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.º 9
0
 public function testGetIdNoSource()
 {
     // Creates a new index 'xodoa' and a type 'user' inside this index
     $indexName = 'xodoa';
     $typeName = 'user';
     $client = new Elastica_Client();
     $index = $client->getIndex($indexName);
     $index->create(array(), true);
     $type = $index->getType($typeName);
     $mapping = new Elastica_Type_Mapping($type);
     $mapping->disableSource();
     $mapping->send();
     // Adds 1 document to the index
     $docId = 3;
     $doc1 = new Elastica_Document($docId, array('username' => 'hans'));
     $type->addDocument($doc1);
     // Refreshes index
     $index->refresh();
     sleep(2);
     $resultSet = $type->search('hans');
     $this->assertEquals(1, $resultSet->count());
     $result = $resultSet->current();
     $this->assertEquals(array(), $result->getSource());
     $this->assertInstanceOf('Elastica_Result', $result);
     $this->assertEquals($indexName, $result->getIndex());
     $this->assertEquals($typeName, $result->getType());
     $this->assertEquals($docId, $result->getId());
     $this->assertGreaterThan(0, $result->getScore());
     $this->assertInternalType('array', $result->getData());
 }
Ejemplo n.º 10
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('id' => 1, 'email' => '*****@*****.**', 'username' => 'hanswurst', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $doc = new Elastica_Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'peter', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $queryString = new Elastica_Query_QueryString('test*');
     $filter1 = new Elastica_Filter_Term();
     $filter1->addTerm('username', 'peter');
     $filter2 = new Elastica_Filter_Term();
     $filter2->addTerm('username', 'qwerqwer');
     $query1 = new Elastica_Query_Filtered($queryString, $filter1);
     $query2 = new Elastica_Query_Filtered($queryString, $filter2);
     $index->refresh();
     $resultSet = $type->search($queryString);
     $this->assertEquals(2, $resultSet->count());
     $resultSet = $type->search($query1);
     $this->assertEquals(1, $resultSet->count());
     $resultSet = $type->search($query2);
     $this->assertEquals(0, $resultSet->count());
 }
Ejemplo n.º 11
0
	public function testMatchDoc() {

		$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);

		$percolator = new Elastica_Percolator($index);
		
		$percolatorName = 'percotest';
		
		$query = new Elastica_Query_Term(array('name' => 'ruflin'));
		$response = $percolator->registerQuery($percolatorName, $query);

		$this->assertTrue($response->isOk());
		$this->assertFalse($response->hasError());

		$doc1 = new Elastica_Document();
		$doc1->add('name', 'ruflin');

		$doc2 = new Elastica_Document();
		$doc2->add('name', 'nicolas');

		$index = new Elastica_Index($index->getClient(), '_percolator');
		$index->refresh();
		
		$matches1 = $percolator->matchDoc($doc1);
		
		$this->assertTrue(in_array($percolatorName, $matches1));
		$this->assertEquals(1, count($matches1));
		
		$matches2 = $percolator->matchDoc($doc2);
		$this->assertEmpty($matches2);
	}
Ejemplo n.º 12
0
	public function testQuery() {

		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('helloworld');

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


		$facet = new Elastica_Facet_Terms('test');
		$facet->setField('name');

		$query = new Elastica_Query();
		$query->addFacet($facet);
		$query->setQuery(new Elastica_Query_MatchAll());

		$index->refresh();

		$response = $type->search($query);
		$facets = $response->getFacets();

		$this->assertEquals(3, count($facets['test']['terms']));
	}	
Ejemplo n.º 13
0
	public function testFilter() {
		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('helloworld');
		
		$type->addDocument(new Elastica_Document(1, array('color' => 'red')));
		$type->addDocument(new Elastica_Document(2, array('color' => 'green')));
		$type->addDocument(new Elastica_Document(3, array('color' => 'blue')));
		
		$index->refresh();
		
		$termQuery = new Elastica_Query_Term(array('color' => 'red'));
		
		$facet = new Elastica_Facet_Query('test');
		$facet->setQuery($termQuery);
		
		$query = new Elastica_Query();
		$query->addFacet($facet);
		
		$resultSet = $type->search($query);
		
		$facets = $resultSet->getFacets();
		
		$this->assertEquals(1, $facets['test']['count']);
	}
Ejemplo n.º 14
0
 public function testGeoPoint()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('point' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Elastica_Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Elastica_Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('point', 30, 40);
     $type->addDocument($doc2);
     $index->refresh();
     // Only one point should be in polygon
     $query = new Elastica_Query();
     $points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16));
     $geoFilter = new Elastica_Filter_GeoPolygon('point', compact('points'));
     $query = new Elastica_Query(new Elastica_Query_MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Elastica_Query();
     $points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16));
     $geoFilter = new Elastica_Filter_GeoPolygon('point', compact('points'));
     $query = new Elastica_Query(new Elastica_Query_MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(2, $type->search($query)->count());
 }
Ejemplo n.º 15
0
 public function testSetSort()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $doc = new Elastica_Document(1, array('name' => 'hello world'));
     $type->addDocument($doc);
     $doc = new Elastica_Document(2, array('firstname' => 'guschti', 'lastname' => 'ruflin'));
     $type->addDocument($doc);
     $doc = new Elastica_Document(3, array('firstname' => 'nicolas', 'lastname' => 'ruflin'));
     $type->addDocument($doc);
     $queryTerm = new Elastica_Query_Term();
     $queryTerm->addTerm('lastname', 'ruflin');
     $index->refresh();
     $query = Elastica_Query::create($queryTerm);
     // ASC order
     $query->setSort(array(array('firstname' => array('order' => 'asc'))));
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     $first = $resultSet->current()->getData();
     $second = $resultSet->next()->getData();
     $this->assertEquals('guschti', $first['firstname']);
     $this->assertEquals('nicolas', $second['firstname']);
     // DESC order
     $query->setSort(array('firstname' => array('order' => 'desc')));
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     $first = $resultSet->current()->getData();
     $second = $resultSet->next()->getData();
     $this->assertEquals('nicolas', $first['firstname']);
     $this->assertEquals('guschti', $second['firstname']);
 }
Ejemplo n.º 16
0
 public function testTest()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('helloworld');
     $mapping = new Elastica_Type_Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')));
     $type->setMapping($mapping);
     $doc = new Elastica_Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
     $type->addDocument($doc);
     $facet = new Elastica_Facet_DateHistogram('dateHist1');
     $facet->setInterval("day");
     $facet->setField("dtmPosted");
     $query = new Elastica_Query();
     $query->addFacet($facet);
     $query->setQuery(new Elastica_Query_MatchAll());
     $index->refresh();
     $response = $type->search($query);
     $facets = $response->getFacets();
     $this->assertEquals(4, $response->getTotalHits());
     $this->assertEquals(2, count($facets['dateHist1']['entries']));
 }
Ejemplo n.º 17
0
	public function testExample() {
		// Creates a new index 'xodoa' and a type 'user' inside this index
		$host = 'localhost';
		$port = 11211;
		$client = new Elastica_Client(array('host' => $host, 'port' => $port, 'transport' => 'Memcache'));

		$index = $client->getIndex('elastica_test1');
		$index->create(array(), true);

		$type = $index->getType('user');


		// Adds 1 document to the index
		$doc1 = new Elastica_Document(1,
			array('username' => 'hans', 'test' => array('2', '3', '5'))
		);
		$type->addDocument($doc1);

		// Adds a list of documents with _bulk upload to the index
		$docs = array();
		$docs[] = new Elastica_Document(2,
			array('username' => 'john', 'test' => array('1', '3', '6'))
		);
		$docs[] = new Elastica_Document(3,
			array('username' => 'rolf', 'test' => array('2', '3', '7'))
		);
		$type->addDocuments($docs);

		// Refresh index
		$index->refresh();
		$this->markTestSkipped('Memcache implementation is not finished yet');
		$resultSet = $type->search('rolf');
	}
Ejemplo n.º 18
0
 public function testResponse()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('helloworld');
     $mapping = new Elastica_Type_Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')));
     $type->setMapping($mapping);
     $doc = new Elastica_Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
     $type->addDocument($doc);
     $doc = new Elastica_Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
     $type->addDocument($doc);
     $query = new Elastica_Query();
     $query->setQuery(new Elastica_Query_MatchAll());
     $index->refresh();
     $resultSet = $type->search($query);
     $engineTime = $resultSet->getResponse()->getEngineTime();
     $shardsStats = $resultSet->getResponse()->getShardsStatistics();
     $this->assertTrue($engineTime != '');
     $this->assertTrue(is_array($shardsStats));
     $this->assertArrayHasKey('total', $shardsStats);
     $this->assertArrayHasKey('successful', $shardsStats);
 }
Ejemplo n.º 19
0
	public function testQuery() {

		$client = new Elastica_Client();
		$index = $client->getIndex('test');
		$index->create(array(), true);
		$type = $index->getType('test');

		$doc = new Elastica_Document(1, array('name' => 'Basel-Stadt'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(2, array('name' => 'New York'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(3, array('name' => 'Baden'));
		$type->addDocument($doc);
		$doc = new Elastica_Document(4, array('name' => 'Baden Baden'));
		$type->addDocument($doc);


		$index->refresh();

		$type = 'text_phrase';
		$field = 'name';

		$query = new Elastica_Query_Fuzzy();
		$query->addField('name', array('value' => 'Baden'));

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

		$this->assertEquals(2, $resultSet->count());
	}
Ejemplo n.º 20
0
 public function testAddIndices()
 {
     $client = new Elastica_Client();
     $search = new Elastica_Search($client);
     $indices = array();
     $indices[] = $client->getIndex('elastica_test1');
     $indices[] = $client->getIndex('elastica_test2');
     $search->addIndices($indices);
     $this->assertEquals(2, count($search->getIndices()));
 }
Ejemplo n.º 21
0
 public function testGetSettings()
 {
     $indexName = 'test';
     $client = new Elastica_Client();
     $index = $client->getIndex($indexName);
     $index->create(array(), true);
     $status = $index->getStatus();
     $settings = $status->getSettings();
     $this->assertInternalType('array', $settings);
     $this->assertTrue(isset($settings['index.number_of_shards']));
 }
Ejemplo n.º 22
0
 public function testGet()
 {
     $client = new Elastica_Client();
     $names = $client->getCluster()->getNodeNames();
     $name = reset($names);
     $node = new Elastica_Node($name, $client);
     $info = new Elastica_Node_Info($node);
     $this->assertInternalType('string', $info->get('os', 'mem', 'total'));
     $this->assertInternalType('array', $info->get('os', 'mem'));
     $this->assertNull($info->get('test', 'notest', 'notexist'));
 }
Ejemplo n.º 23
0
 public function testGetSettings()
 {
     $indexName = 'test';
     $client = new Elastica_Client();
     $index = $client->getIndex($indexName);
     $index->create(array(), true);
     $stats = $index->getStats();
     $this->assertInstanceOf('Elastica_Index_Stats', $stats);
     $this->assertTrue($stats->get('ok'));
     $this->assertEquals(0, $stats->get('_all', 'indices', 'test', 'primaries', 'docs', 'count'));
 }
Ejemplo n.º 24
0
 public function testServerStatus()
 {
     $client = new Elastica_Client();
     $status = $client->getStatus();
     $serverStatus = $status->getServerStatus();
     $this->assertTrue(!empty($serverStatus));
     $this->assertTrue('array' == gettype($serverStatus));
     $this->assertArrayHasKey('ok', $serverStatus);
     $this->assertTrue($serverStatus['ok']);
     $this->assertArrayHasKey('version', $serverStatus);
     $versionInfo = $serverStatus['version'];
     $this->assertArrayHasKey('number', $versionInfo);
 }
Ejemplo n.º 25
0
 public function testShutdown()
 {
     $this->markTestSkipped('This test shuts down the cluster which means the following tests would not work');
     $client = new Elastica_Client();
     $cluster = $client->getCluster();
     $cluster->shutdown('2s');
     sleep(5);
     try {
         $client->getStatus();
         $this->fail('Should throw exception because cluster is shut down');
     } catch (Elastica_Exception_Client $e) {
         $this->assertTrue(true);
     }
 }
Ejemplo n.º 26
0
 public function testServersArray()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $start = microtime(true);
     for ($i = 1; $i <= 10000; $i++) {
         $doc = new Elastica_Document($i, array('test' => 1));
         $type->addDocument($doc);
     }
     // Refresh index
     $index->refresh();
     $end = microtime(true);
     //echo $end - $start;
 }
Ejemplo n.º 27
0
 public function testGetIndexNames()
 {
     $client = new Elastica_Client();
     $cluster = $client->getCluster();
     $indexName = 'elastica_test999';
     $index = $this->_createIndex($indexName);
     $index->delete();
     $cluster->refresh();
     // Checks that index does not exist
     $indexNames = $cluster->getIndexNames();
     $this->assertNotContains($index->getName(), $indexNames);
     $index = $this->_createIndex($indexName);
     $cluster->refresh();
     // Now index should exist
     $indexNames = $cluster->getIndexNames();
     $this->assertContains($index->getname(), $indexNames);
 }
Ejemplo n.º 28
0
 public function testNestedMapping()
 {
     $client = new Elastica_Client();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $this->markTestIncomplete('nested mapping is not set right yet');
     $mapping = new Elastica_Type_Mapping($type, array('test' => array('type' => 'object', 'store' => 'yes', 'properties' => array('user' => array('properties' => array('firstname' => array('type' => 'string', 'store' => 'yes'), 'lastname' => array('type' => 'string', 'store' => 'yes'), 'age' => array('type' => 'integer', 'store' => 'yes')))))));
     $type->setMapping($mapping);
     $doc = new Elastica_Document(1, array('user' => array('firstname' => 'Nicolas', 'lastname' => 'Ruflin', 'age' => 9)));
     print_r($type->getMapping());
     exit;
     $type->addDocument($doc);
     $index->refresh();
     $resultSet = $type->search('ruflin');
     print_r($resultSet);
 }
Ejemplo n.º 29
0
 public function testShutdown()
 {
     $client = new Elastica_Client();
     $nodes = $client->getCluster()->getNodes();
     $count = count($nodes);
     if ($count < 2) {
         $this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
     }
     // Stores node info for later
     $info = $nodes[1]->getInfo();
     $nodes[0]->shutdown('2s');
     sleep(5);
     $client = new Elastica_Client(array('host' => $info->getIp(), 'port' => $info->getPort()));
     $names = $client->getCluster()->getNodeNames();
     // One node less ...
     $this->assertEquals($count - 1, count($names));
 }
Ejemplo n.º 30
0
/**
 * Main search controller.
 * 
 * @param string $key
 */
function find_search($key)
{
    drupal_add_css(drupal_get_path('module', 'find') . '/css/find_search.css', array('group' => CSS_DEFAULT, 'every_page' => true));
    drupal_add_css(drupal_get_path('module', 'find') . '/css/find_print.css', array('group' => CSS_DEFAULT, 'every_page' => true, 'media' => 'print'));
    drupal_add_js('http://maps.google.com/maps/api/js?sensor=false&libraries=geometry,places', array('group' => JS_LIBRARY));
    drupal_add_library('system', 'ui.sortable');
    drupal_add_js(drupal_get_path('module', 'area') . '/css/overlay-style.js');
    drupal_add_js(drupal_get_path('module', 'area') . '/js/geometry.js');
    drupal_add_js(drupal_get_path('module', 'find') . '/js/find.js');
    drupal_add_css(drupal_get_path('module', 'gallery') . '/css/jquery.lightbox.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
    drupal_add_js(drupal_get_path('module', 'gallery') . '/js/jquery.lightbox.js', array('weight' => 100));
    drupal_add_js(drupal_get_path('module', 'gallery') . '/js/gallery.lightbox.js');
    $variables = array('#theme' => 'find.search');
    // fetch $_GET parameters
    $params = find_query_params(array('search' => '', 'geo' => array(), 'date' => array(), 'class' => array(), 'user' => array(), 'family' => array(), 'genus' => array(), 'town' => array(), 'canton' => array(), 'redlist' => array(), 'habitat' => array(), 'image_type' => array(), 'columns' => array(), 'sort' => array()));
    $params['uid'] = $GLOBALS['user']->uid;
    try {
        $client = new Elastica_Client();
        $status = $client->getStatus();
        // ping to make sure elasticsearch is running
        $index = $client->getIndex('naturwerk');
        $parameters = new Parameters($params);
        $variables['#organisms'] = new Organisms($index, $parameters);
        $variables['#sightings'] = new Sightings($index, $parameters);
        $variables['#inventories'] = new Inventories($index, $parameters);
        $variables['#areas'] = new Areas($index, $parameters);
        $variables['#images'] = new Images($index, $parameters);
        // make parameters available to JavaScript
        $parameters = drupal_get_query_parameters();
        if (count($parameters) == 0) {
            $parameters = new stdClass();
            // force empty JSON object
        }
        drupal_add_js(array('find' => array('url' => url($_GET['q']), 'parameters' => $parameters, 'geo' => $params['geo'])), 'setting');
        $variables['#key'] = $key;
        $variables['#current'] = $variables['#' . $key];
        $output = array();
        $output['search'] = $variables;
        return $output;
    } catch (Elastica_Exception_Client $e) {
        watchdog('find', $e->getMessage(), array(), WATCHDOG_ERROR);
        drupal_set_message(t('Search error. Elasticsearch running?'), 'error');
        return array();
    }
}