Permalink
Browse files

Adding description of stats support to docs.

  • Loading branch information...
1 parent 61bb0e2 commit 9c250a8154da230a2b061f202f6c60184ed7d118 Ranjit Chacko committed with toastdriven Mar 19, 2012
Showing with 85 additions and 1 deletion.
  1. +6 −0 docs/searchquery_api.rst
  2. +78 −1 docs/searchqueryset_api.rst
  3. +1 −0 haystack/backends/__init__.py
@@ -250,6 +250,12 @@ to the rest of the ``SearchQuerySet``.
Allows backends with support for "More Like This" to return results
similar to the provided instance.
+``add_stats_query``
+~~~~~~~~~~~~~~~~~~~
+.. method:: SearchQuery.add_stats_query(self,stats_field,stats_facets)
+
+Adds stats and stats_facets queries for the Solr backend.
+
``add_highlight``
~~~~~~~~~~~~~~~~~
@@ -360,9 +360,40 @@ Spatial: Adds a distance-based search to the query.
See the :ref:`ref-spatial` docs for more information.
+``stats``
+~~~~~~~~~
+
+.. method:: SearchQuerySet.stats(self, field):
+
+Adds stats to a query for the provided field. This is supported on
+Solr only. You provide the field (from one of the ``SearchIndex``
+classes) you would like stats on.
+
+In the search results you get back, stats will be populated in the
+``SearchResult`` object. You can access them via the `` stats_results`` method.
+
+Example::
+
+ # Get stats on the author field.
+ SearchQuerySet().filter(content='foo').stats('author')
+
+``stats_facet``
+~~~~~~~~~~~~~~~
+.. method:: SearchQuerySet.stats_facet(self, field,
+.. facet_fields=None):
+
+Adds stats facet for the given field and facet_fields represents the
+faceted fields. This is supported on Solr only.
+
+Example::
+
+ # Get stats on the author field, and stats on the author field
+ faceted by bookstore.
+ SearchQuerySet().filter(content='foo').stats_facet('author','bookstore')
+
+
``distance``
~~~~~~~~~~~~
-
.. method:: SearchQuerySet.distance(self, field, point):
Spatial: Denotes results must have distance measurements from the
@@ -632,6 +663,52 @@ Example::
# 'queries': {}
# }
+``stats_results``
+~~~~~~~~~~~~~~~~~
+
+.. method:: SearchQuerySet.stats_results(self):
+
+Returns the stats results found by the query.
+
+ This will cause the query to
+execute and should generally be used when presenting the data (template-level).
+
+You receive back a dictionary with three keys: ``fields``, ``dates`` and
+``queries``. Each contains the facet counts for whatever facets you specified
+within your ``SearchQuerySet``.
+
+.. note::
+
+ The resulting dictionary may change before 1.0 release. It's fairly
+ backend-specific at the time of writing. Standardizing is waiting on
+ implementing other backends that support faceting and ensuring that the
+ results presented will meet their needs as well.
+
+Example::
+
+ # Count document hits for each author.
+ sqs = SearchQuerySet().filter(content='foo').stats('price')
+
+ sqs.stats_results()
+
+ # Gives the following response
+ # {
+ # 'stats_fields':{
+ # 'author:{
+ # 'min': 0.0,
+ # 'max': 2199.0,
+ # 'sum': 5251.2699999999995,
+ # 'count': 15,
+ # 'missing': 11,
+ # 'sumOfSquares': 6038619.160300001,
+ # 'mean': 350.08466666666664,
+ # 'stddev': 547.737557906113
+ # }
+ # }
+ #
+ # }
+
+
``spelling_suggestion``
~~~~~~~~~~~~~~~~~~~~~~~
@@ -706,6 +706,7 @@ def more_like_this(self, model_instance):
self._mlt_instance = model_instance
def add_stats_query(self,stats_field,stats_facets):
+ """Adds stats and stats_facets queries for the Solr backend."""
self.stats[stats_field] = stats_facets
def add_highlight(self):

0 comments on commit 9c250a8

Please sign in to comment.