當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Document::addGeoPoint方法代碼示例

本文整理匯總了PHP中Elastica\Document::addGeoPoint方法的典型用法代碼示例。如果您正苦於以下問題:PHP Document::addGeoPoint方法的具體用法?PHP Document::addGeoPoint怎麽用?PHP Document::addGeoPoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Elastica\Document的用法示例。


在下文中一共展示了Document::addGeoPoint方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGeoPoint

 public function testGeoPoint()
 {
     $client = $this->_getClient();
     $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 Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new 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 Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
開發者ID:viz,項目名稱:wordpress-fantastic-elasticsearch,代碼行數:32,代碼來源:GeoDistanceTest.php

示例2: testGeoPoint

 /**
  * @group functional
  */
 public function testGeoPoint()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('location' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('location', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('location', 30, 40);
     $type->addDocument($doc2);
     $index->refresh();
     // Only one point should be in polygon
     $query = new Query();
     $points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(2, $type->search($query)->count());
 }
開發者ID:vinusebastian,項目名稱:Elastica,代碼行數:33,代碼來源:GeoPolygonTest.php

示例3: testAddGeoPoint

 /**
  * @group unit
  */
 public function testAddGeoPoint()
 {
     $doc = new Document();
     $returnValue = $doc->addGeoPoint('point', 38.89859, -77.035971);
     $this->assertInstanceOf('Elastica\\Document', $returnValue);
 }
開發者ID:MediaWiki-stable,項目名稱:1.26.1,代碼行數:9,代碼來源:DocumentTest.php


注:本文中的Elastica\Document::addGeoPoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。