public function testSearchDistance() { $searchQuery = new CM_Elasticsearch_Query_Location(); $location = new CM_Model_Location(CM_Model_Location::LEVEL_CITY, self::$_cityId); $searchQuery->sortDistance($location); $source = new CM_PagingSource_Elasticsearch_Location($searchQuery); $locationList = $source->getItems(); $this->assertEquals(array('id' => self::$_cityId, 'level' => CM_Model_Location::LEVEL_CITY), reset($locationList)); }
/** * @param string $term * @param int $minLevel * @param int $maxLevel * @param CM_Model_Location|null $location */ public function __construct($term, $minLevel, $maxLevel, CM_Model_Location $location = null) { $term = (string) $term; $minLevel = (int) $minLevel; $maxLevel = (int) $maxLevel; $query = new CM_Elasticsearch_Query_Location(); $query->filterLevel($minLevel, $maxLevel); if (strlen($term) > 0) { $query->queryName($term); } $query->sortLevel(); if ($location) { $query->sortDistance($location); } $query->sortScore(); $source = new CM_PagingSource_Elasticsearch_Location($query); $source->enableCacheLocal(); parent::__construct($source); }