Skip to content

Commit

Permalink
Merge pull request #28 from dmyers/elasticsearch-location
Browse files Browse the repository at this point in the history
Added location support to elasticsearch driver using using geopoint
  • Loading branch information
mmanos committed Jun 22, 2015
2 parents dba8569 + dfc6135 commit c61f58f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Mmanos/Search/Index/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function newQuery()
{
return array(
'index' => $this->name,
'body' => array('query' => array('bool' => array())),
'body' => array('query' => array()),
);
}

Expand All @@ -71,10 +71,6 @@ public function newQuery()
*/
public function addConditionToQuery($query, array $condition)
{
if (array_get($condition, 'lat')) {
return $query;
}

$value = trim(array_get($condition, 'value'));
$field = array_get($condition, 'field', '_all');

Expand Down Expand Up @@ -107,6 +103,19 @@ public function addConditionToQuery($query, array $condition)
'min_similarity' => $fuzziness,
);
}
elseif (array_get($condition, 'lat')) {
$definition = array(
'distance' => $condition['distance'].'m',
'_geoloc' => array(
'lat' => $condition['lat'],
'lon' => $condition['long'],
),
);

$query['body']['query']['filtered']['filter']['geo_distance'] = $definition;

return $query;
}
else {
$is_phrase = (!empty($condition['phrase']) || !empty($condition['filter']));
$match_type = 'multi_match';
Expand All @@ -117,7 +126,7 @@ public function addConditionToQuery($query, array $condition)
);
}

$query['body']['query']['bool'][$occur][][$match_type] = $definition;
$query['body']['query']['filtered']['query']['bool'][$occur][][$match_type] = $definition;

return $query;
}
Expand Down

0 comments on commit c61f58f

Please sign in to comment.