Creating a great Geospatial search experience for D8 users

We know location based search is slowly becoming popular and a must have for any content website in the recent era, Drupal 8 needs to have a drop-in solution for geo-spatial search. Right now, there are some alpha modules existing but these modules need some serious investment for them to become production ready. Ultimately, it should be possible for a site builder to download these modules and have an intuitive way to enable geospatial search, either by using a central point or using a box-search (boundaries wherein the search should stay) and by recognizing the current location of the user and adjust the search results based on that. As well as it should support both Apache Solr and MySql server as backend for indexing location data.

Indexing location values

As drupal natively does not support geo data type, there are some modules like geofield, location, etc.  which provide field types and help in storing spatial data in database. User can input location data to the nodes, users and taxonomy terms via map or by manually entering decimal values. Search_API_Location Module adds a new data type, "Latitude/longitude" to the "Fields" form of Search API indexes.


  Filtering and sorting location values

  • Search_API_Location provides two sub-modules for Pages and Views support which are primarily used for searching spatial data.

  • The below image shows the basic workflow of sorting and filtering data by Search_API. The Search_API_Location module adds location search capabilities to Search API views. It adds both filters and contextual filters for filtering by proximity to a specified location.

  • Location_Search_pages provides simple search pages, not using Views or any other modules. They can be used when a view would be unnecessarily slow, or for quickly testing out functionality. They also provide search blocks for starting a search from anywhere on the site.This avoids overhead when using only one of the methods, cleanly separates the code and makes it easier to integrate this with other search methods.

 Task for porting the module to D8

  • D8 replaces similar type of functionality with Plugins instead of hooks. Search API Location adds plugins like LocationDataType to data_type plugin type of Seach_API module. It extends DataTypePluginBase class and defines a new data type i.e lat/long data to be indexed by Search API.

  • However, data type that is to be indexed completely depends upon the upstream backend server for all spatial calculations. In D7 only Apache Solr was stable. But in  D8, neither Solr nor My-SQL is stable.  For the time being my proposal aims for stable support of Solr server for indexing location data  in D8.

  • Search API uses Search_Api_Solr to interact with Solr server and  Search_API_Solr uses Solarium php library to interact with Solr.  ( Solr server is a java based application )

  • For Solr backend to be supported, we need to add location as a supported DataType for SearchApiSolrBackend. Here is the stated  issue  (Adding location as a supported DataType for SearchApiSolr Backend) which implicitly prevents the Search_API_Location module to grow further. Currently, I am working on this issue and needs some more research as it is related to both Search_API and Search_API_Solr.  

  • Search_API provides various types of views handler plugin type to other modules to extend its views functionality. So, Search_API_Location provides SearchApiFilterLocation plugin to integrate with filter plugin type of views module. Along with this it provides its own plugin type like location_input to be implemented by other modules like geocoder, map, etc.

  • In D7, search_API_location_map was a submodule which adds an exposed filter plugin for users to enter location by clicking on a map and specifying the range of radius within which data is to be searched as shown in the below figure; But in D8, it is ported as a location input plugin. Yet the transition is unclear and a part of the research phase in order to work towards a solution for Drupal8.  

  • A plugin manager service class is needed which helps discover and instantiate our required plugins of particular type. Plugins like GeoCode, Map and Raw are extended classes of LocationInputPluginBase implementing LocationInputInterface which are    discovered by LocationInputPluginManager .

  • Every plugin have their own configuration form. Some of the methods like form validation, submission, etc. are missing as of now. So, I need to complete these form handler methods of all the plugin classes. In addition to it, the API has some basic functionality to check the units of user input distance within which the search will be performed and its validity, etc. So, I need to write these methods.

  • Distance calculation and sorting are mostly provided by backend server class (e.g.- Solr provides its own method Read more).  If the backend server does not provide  these, then search_api_location_calculate_distance method needs to be called which uses  Haversine formula to measure distance between two points in a sphere.

The porting of above project to D8 is applied by dbjpanda as a proposal for Google summer of code'2017  and if accepted, will be funded by Google . The complete road-map or progress of the project will be posted in next articles.  Stay tuned, comment and give your feedback