Ticket #798 (closed Defect: worksforme)

Opened 6 years ago

Last modified 6 years ago

dm4-geomaps: Lat, Long, is IndexMode probably wrong?

Reported by: Malte Owned by: jri
Priority: Major Milestone: Release 4.7
Component: DeepaMehta Standard Distribution Version: 4.4
Keywords: Cc: Malte
Complexity: 1 Area:
Module: deepamehta-geomaps

Description

I stored geo-coordinates as follows, coordinates being a double[]

geoCoordinates.put("dm4.geomaps.latitude", coordinates[1]);

Then i tried to fetch the topic to re-use it (aggregate its parent (geo coordinate) to a second domain topic) but sadly the following

dms.getTopic("dm4.geomaps.latitude", new SimpleValue(coordinates[1]));

.. did not return the wanted topic but is empty.

What am i doing wrong here?

May it be that Latitude and Longitude's Index Mode is NOT Key and this prevents me of fetching those by exact value?
see https://github.com/jri/deepamehta/blob/master/modules/dm4-geomaps/src/main/resources/migrations/migration1.json

Thanks for your support!

Change History

comment:1 Changed 6 years ago by jri

Yes, indeed, fetching a Latitude topic by its exact value is not supported. The long/lat values are not indexed.
When defining the Geomaps model I did not see an application would need that.

comment:2 follow-up: ↓ 3 Changed 6 years ago by jri

Your application could set the index mode itself.
Since DM 4.3 you can add index modes to types afterwards:

dms.getTopicType("dm4.geomaps.latitude").addIndexMode(IndexMode.KEY);

Existing topics/associations are indexed subsequently then.
See #649

comment:3 in reply to: ↑ 2 Changed 6 years ago by jri

Replying to jri:

Existing topics/associations are indexed subsequently then.

That means existing content is reindexed automatically.

comment:4 Changed 6 years ago by jri

2 more general hints:

  • Consider using the GeoCoordinate? helper class to store a long/lat pair:
    import de.deepamehta.plugins.geomaps.model.GeoCoordinate;
    
    GeoCoordinate geoCoord = new GeoCoordinate(long, lat);
    double lon = geoCoord.lon;
    double lat = geoCoord.lat;
    
  • Consider attaching a dm4.geomaps.geo_coordinate_facet to your type.

You can use the Geomaps Service then, e.g.:

// Returns the geo coordinate of a geo-facetted topic (e.g. an Address),
// or <code>null</code> if no geo coordinate is stored.
GeoCoordinate getGeoCoordinate(Topic geoTopic);

// Returns the geo coordinate encoded in a Geo Coordinate topic.
GeoCoordinate geoCoordinate(Topic geoCoordTopic);

comment:5 follow-up: ↓ 7 Changed 6 years ago by Malte

I am very glad to be able to make use of this new feature, great. I could just work it out through writing a new migration which rolls out these new IndexModes? on the dm4-wikidata-toolkit "geo-fronts" branch.

About your second hint i have a question:
what would be the benefit of using a facet_type as intermediary instead of modelling it directly as a child type? I am just curious to understand this better cause currently i modeled the geo_coordinate topic as an "aggregated many" directly to tjhe "wikidata item".

Thanks you for your help and your hints on improving the model with facets!

comment:6 Changed 6 years ago by Malte

  • Status changed from new to closed
  • Resolution set to worksforme

comment:7 in reply to: ↑ 5 Changed 6 years ago by jri

Replying to Malte:

About your second hint i have a question:
what would be the benefit of using a facet_type as intermediary instead of modelling it directly as a child type?

The Facets service is useful when it comes to decoupling. Note that e.g. the Contacts module (with its Address type) knows nothing about geo coordinates and geocoding. This is the very responsibility of the Geomaps module. However the Geomaps module doesn't want to extend the Address type in order to be not intrusive to the Contacts module. Instead the Geomaps module attaches and maintains a "geo facet" to each Address instance. This realizes a "loose coupling" and thus supports maintainability.

Im case loose coupling is not an aspect of your application there might be no indication for using DM's facet service.

http://en.wikipedia.org/wiki/Loose_coupling

Note: See TracTickets for help on using tickets.