Geospatial search with SOLR

12,647 views

Published on

This was my presentation for Drupalcamp Gent 2012. Presented on Friday May 25, 2012.

Published in: Technology
3 Comments
12 Likes
Statistics
Notes
No Downloads
Views
Total views
12,647
On SlideShare
0
From Embeds
0
Number of Embeds
28
Actions
Shares
0
Downloads
0
Comments
3
Likes
12
Embeds 0
No embeds

No notes for slide

Geospatial search with SOLR

  1. 1. Geospatial search with SOLR Nicolas Leroy
  2. 2. Geospatial search with SOLR
  3. 3. Who am I?Nicolas Leroy - AUSY/DataflowTwitter: nicolasleroyDrupal.org: http://drupal.org/user/3527
  4. 4. SOLR
  5. 5. SOLRSolr is the popular, blazing fast open sourceenterprise search platform from the ApacheLucene project.Its major features include powerful full-textsearch, hit highlighting, faceted search,dynamic clustering, database integration, richdocument handling, and geospatial search.Solr is written in Java
  6. 6. SOLRMore information:http://lucene.apache.org/solr/
  7. 7. SOLRSingle core vs MulticoreOne index vs Multiple indexes
  8. 8. Multicore
  9. 9. MulticoreStartup script:cd /Applications/apache-solr-3.5.0/serverjava -Dsolr.solr.home=multicore -jar start.jar
  10. 10. Geospatial search
  11. 11. Geospatial search: definitionwikipedia:Geomatics (also known as geospatialtechnology or geomatics engineering) is thediscipline of gathering, storing, processing, anddelivering geographic information, orspatially referenced information.
  12. 12. Latitude and longitude
  13. 13. Latitude and longitudeLatitude = horizontal linesLongitude = vertical lines
  14. 14. World map
  15. 15. Geolocation
  16. 16. Geolocation: ground markSurveyor-General Victoria (SGV) is responsiblefor Victoria’s Geodetic Survey Control Network.This is the infrastructure used to provideaccurate position and height referencing acrossVictoria. It is made up of 140,000 ground markshttp://www.dse.vic.gov.au/property-titles-and-maps/surveying-home-page/government-survey-services/victorias-survey-infrastructure
  17. 17. Drupal + SOLR
  18. 18. Drupal + SOLR: modules•  search_api + search_api_solr•  apachesolr
  19. 19. Geospatial Options•  geofield + geocoder + search_api + search_api_location•  location + search_api + search_api_location•  location + gmap + apachesolr + apachesolr_location•  apachesolr_geo still a sandbox, not much information.
  20. 20. Drupal + SOLRDrupal:http://drupal.org/startApachesolr modulehttp://drupal.org/project/apachesolrDownload SOLR:http://www.apache.org/dyn/closer.cgi/lucene/ solr/3.6.0
  21. 21. Drupal + SOLRNice tutorial:http://www.nickveenhof.be/blog/simple-guide- install-apache-solr-3x-drupal-7Check his blog for screencasts:http://www.nickveenhof.be/
  22. 22. Our Story•  Drupal site•  Using SOLR with apachesolr module•  Location moduleProblem:Location information wasnt indexed
  23. 23. Drupal: Location moduleThe Location module allows real-worldgeographic locations to be associated withDrupal nodes.http://drupal.org/project/location
  24. 24. Location in actionhttp://drupal7.local:8080/node/1/edit
  25. 25. Why not indexed?SOLR doesnt know what to do with this customfield.And this field contains multiple values (street,city, province, country,...)
  26. 26. SolutionWe wrote some custom code to:•  index location information properly•  generate facets•  provide a search form for geospatial search (longitude, latitude + radius)We changed schema.xml to use a"solr.LatLonType" field.
  27. 27. Schema?
  28. 28. Schema.xml?The schema.xml file contains all of the detailsabout which fields your documents cancontain, and how those fields should be dealtwith when adding documents to the index, orwhen querying those fields.Schema.xml comes with the apachesolrmodule and is configured to handle drupalcontent.
  29. 29. Schema.xml?<!-- A specialized field for geospatial search. Ifindexed, this fieldType must not be multivalued.--><fieldType name="location"class="solr.LatLonType"subFieldSuffix="_coordinate"/>
  30. 30. Schema.xmlThis field is now included in schema.xml thatcomes with apachesolr module.
  31. 31. Code
  32. 32. Index location informationhook_apachesolr_update_index(&$document,$node) = DEPRECATEDNow use:hook_index_document_build_ENTITYTYPE
  33. 33. Create new facetshook_facetapi_facet_info($searcher_info)
  34. 34. apachesolr_location modulehttp://drupal.org/project/apachesolr_location
  35. 35. Map fields
  36. 36. Indexing callback
  37. 37. Create facets
  38. 38. Doing the geospatial searchAdding a part to the querystring whensearching:&spatial=[lat]_[long]_[radius]hook_apachesolr_query_alter($query)
  39. 39. hook_apachesolr_query_alter$query->addParam(fq, "{!geofiltsfield=locs_coordinates" . " pt=" . $keys[0] . , .$keys[1] . " d=" . $distance . "}");{!geofilt sfield=locs_coordinates pt=50.879816,4.706429 d=10}
  40. 40. Too hacky (via url)Should be done with querytypes.
  41. 41. Small Demohttp://drupal7.local:8080
  42. 42. Future?
  43. 43. Future•  Adding city + radius box•  Getting coordinates of the city•  Search for items within that range•  Adding visualisation•  Settings UI: miles or km,…What would you add? Let us know!http://drupal.org/project/apachesolr_location
  44. 44. Feedback & follow-up:http://drupalcampgent.be/feedback

×