PHRAS-1809_Geoinfos-in-index

Add a "location" field in records (type="geo_point"), populated with same values as "Longitude" and "Latitude" technical fields.
This commit is contained in:
Jean-Yves Gaulier
2018-04-18 18:06:31 +02:00
parent 993f21dd2e
commit 4164b6dd42
4 changed files with 31 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ class FieldMapping
const TYPE_SHORT = 'short';
const TYPE_BYTE = 'byte';
const TYPE_IP = 'ip';
const TYPE_GEO_POINT = 'geo_point';
// Compound types
const TYPE_OBJECT = 'object';
@@ -48,6 +49,7 @@ class FieldMapping
self::TYPE_SHORT,
self::TYPE_BYTE,
self::TYPE_IP,
self::TYPE_GEO_POINT,
self::TYPE_OBJECT,
self::TYPE_COMPLETION
);

View File

@@ -156,8 +156,17 @@ SQL;
$position->set($tag_name, $value);
// Try to output complete position
if ($position->isComplete()) {
$records[$id]['metadata_tags']['Longitude'] = $position->getSignedLongitude();
$records[$id]['metadata_tags']['Latitude'] = $position->getSignedLatitude();
$lon = $position->getSignedLongitude();
$lat = $position->getSignedLatitude();
$records[$id]['metadata_tags']['Longitude'] = $lon;
$records[$id]['metadata_tags']['Latitude'] = $lat;
$records[$id]["location"] = [
"lat" => $lat,
"lon" => $lon
];
unset($this->gps_position_buffer[$id]);
}
}

View File

@@ -73,6 +73,8 @@ class RecordIndex implements MappingProvider
$mapping->addIntegerField('height')->disableIndexing();
$mapping->addIntegerField('size')->disableIndexing();
$mapping->addGeoPointField('location')->disableIndexing();
$mapping->addDateField('created_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION);
$mapping->addDateField('updated_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION);

View File

@@ -45,6 +45,15 @@ class MappingBuilder
return $this->mapping->addField(new FieldMapping($name, FieldMapping::TYPE_INTEGER));
}
/**
* @param string $name
* @return FieldMapping
*/
public function addGeoPointField($name)
{
return $this->mapping->addField(new FieldMapping($name, FieldMapping::TYPE_GEO_POINT));
}
/**
* @param string $name
* @return FieldMapping