Permalink
Browse files

Added geospatial search support!

I have anxiously waited to add this feature for almost 3 years now.
Support is finally present in more than one backend & I was
generously given some paid time to work on implementing this.

Thanks go out to:

  * CMGdigital, who paid for ~50% of the development of this feature
    & were awesomely supportive.
  * Jannis Leidel (jezdez), who did the original version of this
    patch & was an excellent sounding board.
  * Adam Fast, for patiently holding my hand through some of the
    geospatial confusions & for helping me verify GeoDjango
    functionality.
  * Justin Bronn, for the great work he originally did on
    GeoDjango, which served as a point of reference/inspiration
    on the API.

And thanks to all others who have submitted a variety of
patches/pull requests/interest throughout the years trying to get
this feature in place.
  • Loading branch information...
1 parent 419550a commit ad79f05b3ccdb53bfddae1e9d488f31968a57704 @toastdriven toastdriven committed Dec 17, 2011
View
@@ -17,7 +17,7 @@ Thanks to
* Brian Rosner for various patches.
* Richard Boulton for feedback and suggestions.
* Cyberdelia for feedback and patches.
- * Jannis Leidel for consistently "walking behind the elephant" and cleaning up the setup.py.
+ * Jannis Leidel for consistently "walking behind the elephant", cleaning up the setup.py & the initial geospatial implementation.
alex
alex Dec 17, 2011

Oxford comma!

* Ask Solem for for patching the setup.py.
* Ben Spaulding for feedback and documentation patches.
* smulloni for various patches.
@@ -55,4 +55,5 @@ Thanks to
* a multiprocessing-enabled version of ``update_index``.
* the addition of ``--start/--end`` options in ``update_index``.
* the ability to specify both apps & models to ``update_index``.
+ * A significant portion of the geospatial & function query features.
* Aram Dulyan (Aramgutang) for fixing the included admin class to be Django 1.4 compatible.
View
@@ -26,12 +26,12 @@ you up and running:
.. toctree::
:maxdepth: 2
-
+
tutorial
-
+
.. toctree::
:maxdepth: 1
-
+
views_and_forms
templatetags
glossary
@@ -41,7 +41,7 @@ you up and running:
other_apps
installing_search_engines
debugging
-
+
migration_from_1_to_2
@@ -53,14 +53,15 @@ you may want to include in your application.
.. toctree::
:maxdepth: 1
-
+
best_practices
highlighting
faceting
autocomplete
boost
multiple_index
rich_content_extraction
+ spatial
Reference
@@ -71,14 +72,14 @@ looking for API documentation and advanced usage as detailed in:
.. toctree::
:maxdepth: 2
-
+
searchqueryset_api
searchindex_api
searchfield_api
searchresult_api
searchquery_api
searchbackend_api
-
+
architecture_overview
backend_support
settings
@@ -94,7 +95,7 @@ additional backends:
.. toctree::
:maxdepth: 1
-
+
running_tests
creating_new_backends
@@ -11,18 +11,19 @@ Official Download Location: http://www.apache.org/dyn/closer.cgi/lucene/solr/
Solr is Java but comes in a pre=packaged form that requires very little other
than the JRE and Jetty. It's very performant and has an advanced featureset.
-Haystack requires Solr 1.3+. Installation is relatively simple::
+Haystack suggests using Solr 3.5+, though it's possible to get it working on
+Solr 1.4 with a little effort. Installation is relatively simple::
- curl -O http://apache.mirrors.tds.net/lucene/solr/1.4.1/apache-solr-1.4.1.tgz
- tar xvzf apache-solr-1.4.1.tgz
- cd apache-solr-1.4.1
+ curl -O http://apache.mirrors.tds.net/lucene/solr/3.5.0/apache-solr-3.5.0.tgz
+ tar xvzf apache-solr-3.5.0.tgz
+ cd apache-solr-3.5.0
cd example
java -jar start.jar
You'll need to revise your schema. You can generate this from your application
(once Haystack is installed and setup) by running
``./manage.py build_solr_schema``. Take the output from that command and place
-it in ``apache-solr-1.4.1/example/solr/conf/schema.xml``. Then restart Solr.
+it in ``apache-solr-3.5.0/example/solr/conf/schema.xml``. Then restart Solr.
You'll also need a Solr binding, ``pysolr``. The official ``pysolr`` package,
distributed via PyPI, is the best version to use (2.1.0+). Place ``pysolr.py``
View
@@ -32,6 +32,7 @@ Included with Haystack are the following field types:
* ``EdgeNgramField``
* ``FloatField``
* ``IntegerField``
+* ``LocationField``
* ``MultiValueField``
* ``NgramField``
@@ -63,13 +64,13 @@ example::
from haystack import indexes
from myapp.models import Note
-
-
+
+
class NoteIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
pub_date = indexes.DateTimeField(model_attr='pub_date')
-
+
def get_model(self):
return Note
View
@@ -257,6 +257,28 @@ similar to the provided instance.
Adds highlighting to the search results.
+``add_within``
+~~~~~~~~~~~~~~~~~
+
+.. method:: SearchQuery.add_within(self, field, point_1, point_2):
+
+Adds bounding box parameters to search query.
+
+``add_dwithin``
+~~~~~~~~~~~~~~~~~
+
+.. method:: SearchQuery.add_dwithin(self, field, point, distance):
+
+Adds radius-based parameters to search query.
+
+``add_distance``
+~~~~~~~~~~~~~~~~~
+
+.. method:: SearchQuery.add_distance(self, field, point):
+
+Denotes that results should include distance measurements from the
+point passed in.
+
``add_field_facet``
~~~~~~~~~~~~~~~~~~~
@@ -320,6 +320,34 @@ Example::
# Count document hits for authors that start with 'jo' within the index.
SearchQuerySet().filter(content='foo').query_facet('author', 'jo*')
+``query_facet``
+~~~~~~~~~~~~~~~
+
+.. method:: SearchQuerySet.within(self, field, point_1, point_2):
+
+Spatial: Adds a bounding box search to the query.
+
+See the :ref:`spatial` docs for more information.
+
+``query_facet``
+~~~~~~~~~~~~~~~
+
+.. method:: SearchQuerySet.dwithin(self, field, point, distance):
+
+Spatial: Adds a distance-based search to the query.
+
+See the :ref:`spatial` docs for more information.
+
+``query_facet``
+~~~~~~~~~~~~~~~
+
+.. method:: SearchQuerySet.distance(self, field, point):
+
+Spatial: Denotes results must have distance measurements from the
+provided point.
+
+See the :ref:`spatial` docs for more information.
+
``narrow``
~~~~~~~~~~
@@ -23,6 +23,11 @@ The class exposes the following useful attributes/properties:
* ``object`` - The actual model instance (lazy loaded).
* ``model`` - The model class.
* ``verbose_name`` - A prettier version of the model's class name for display.
+* ``verbose_name_plural`` - A prettier version of the model's *plural* class name for display.
+* ``search_index`` - Returns the ``SearchIndex`` class associated with this
+ result.
+* ``distance`` - On geo-spatial queries, this returns a ``Distance`` object
+ representing the distance the result was from the focused point.
Method Reference
Oops, something went wrong.

0 comments on commit ad79f05

Please sign in to comment.