Skip to content

Instantly share code, notes, and snippets.

@tisto
Created September 3, 2014 15:31
Show Gist options
  • Save tisto/cb579163a571266b852b to your computer and use it in GitHub Desktop.
Save tisto/cb579163a571266b852b to your computer and use it in GitHub Desktop.
==============================================================================
How to implement a geospatial search with collective.solr
==============================================================================
Solr
----
Configure a Solr Instance with collective.recipe.solrinstance.
Add a geolocation index and a dynamic '*_coordinate' index to the Solr
configuration (buildout.cfg)::
[solr]
recipe = collective.recipe.solrinstance
...
index =
name:geolocation type:location indexed:true stored:true
...
additionalFieldConfig =
<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>
Remove solr config directory (because c.r.solrinstance sometimes fail to
override the Solr configuration)::
$ rm -rf parts/solr
Run buildout::
$ bin/buildout
Start Plone/Solr::
$ bin/instance fg
$ bin/solr-instance fg
Check if Solr is up and running::
localhost:8983/solr/
Plone
-----
Create Dexterity or Archetypes type with a Text field 'geolocation' (interfaces.py)::
class IGeodataBehavior(model.Schema):
geolocation = schema.Text(
title=_("Geolocation"),
required=False
)
Create an indexer for the geolocation field (profiles/default/catalog.xml)::
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
<index name="geolocation" meta_type="FieldIndex">
<indexed_attr value="geolocation" />
</index>
</object>
Restart Plone Instance, and reinstall your product or reindex the geolocation
Index manually. You might also have to run a Solr reindex.
Then you should be able to query
Query Solr::
http://localhost:8090/solr/collection1/select?q=*%3A*&fq={!geofilt+sfield%3Dgeolocation}&wt=json&indent=true&spatial=true&pt=50%2C7&sfield=geolocation&d=7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment