hi there,
i have a question in regards how to best integrate with the views module for a use case, i will explain in more detail below. basically is it feasible to implement aggregation similarly to how views does it, but not in mysql but in php?
background story
i'm currently working on a research project that deals with server-side clustering of geospatial data in drupal: http://drupal.org/project/geocluster
the clustering will work similarly to http://www.crunchpanorama.com/ and therefore combine points that overlap by comparing their distances.
displaying points on a map is yet another great use case for the views module, and has already been implemented by modules like openlayers, geofield and others. i want my solution to integrate as cleanly as possible with drupals best-practice modules.
the two main approaches that i want to implement are
- cluster views results in php (average users will like that for simplicity)
- cluster in apache solr with search_api (advanced users will like that for performance)
i have some draft code, that already combines points in a views result but i don't know how to manipulate the views result in order to replace two points with a cluster of those: http://drupalcode.org/project/geocluster.git/blob/refs/heads/7.x-1.x:/vi...
you might also think of this like replacing the original result items with fake entities.
thanks for any input that might lead me into the right direction!
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views_post_execute_query_hook.patch | 736 bytes | dasjo |
Comments
Comment #1
dasjohad some good discussions with dawehner.
pasting irc log for reference:
Comment #2
dasjoi have further developed my prototype on clustering points using php. the current implementation builds upon a patch, but that might not be the final solution as explained further.
the geocluster_handler_field_geofield doesn't contain any logic, but serves for configuration of the clustering.
the Geocluster class currently depends on the field_handler. i think the custom field_handler won't be necessary, instead it should be possible to create some kind of views plugin that takes over the configuration options and hooks in, where i currently use my implementation of a new hook_views_post_execute_query (see attached patch).
also, related - we have discussed splitting up views_handler_field_field::post_execute a bit:
i have an equal implementation of entities_by_type.
in addition to that, the load_entity_fields method is similar to the load entities part, but avoids doing unnecessary entity loads for result items that will be clustered anyways.
Comment #3
dawehnerIt would be cool to document this hook in views.api.php to tell people when exactly this hook should be used.
Comment #4
dasjoyes, of course. but i'm still not convinced that this hook is the right approach to solving my problem:
so instead of storing configuration in a custom field_handler, i would like to be able to create a plugin/handler that alters views results after query execution. i was looking into altering views_object_types() but i can't see a straight forward approach to doing this, as the type of plugin/handler isn't in the views apis yet.
Comment #5
dasjoafter having some good conversation with dawehner and him actually drafting code for me (thanks!!), i was able to make some progress here.
i have moved from a custom field handler to using a custom views_plugin_display_extender to store clustering configuration: GeoclusterViewsDisplayExtender will capture all settings required for clustering.
the actual clustering is still invoked using the above patch for adding
hook_views_post_execute_query, see #2.that approach seems ok to me for now.
Comment #6
mpgeek commentedNeed to evaluate here if this is already covered in D8 in general. This is of immediate use for #2578785: Large-scale location mapping in Drupal 8 (Views). Adding as a related.
Comment #7
chris matthews commentedThe 3 year old patch in #2 to views_plugin_query_default.inc applied cleanly to the latest views 7.x-3.x-dev and if still relevant needs to be reviewed.