Skip to content

Commit

Permalink
Merge pull request #70 from Princeton-CDH/feature/custom-queryset-result
Browse files Browse the repository at this point in the history
Make it possible to customize queryset result doc
  • Loading branch information
rlskoeser committed Feb 7, 2022
2 parents d359303 + f5d0e59 commit 89de6a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
CHANGELOG
=========

0.9
---

* When subclassing ``SolrQuerySet``, result documents can now be customized by extending ``get_result_document``

0.8.1
-----
* Exclude proxy models when collecting indexable subclasses
Expand Down
8 changes: 6 additions & 2 deletions parasolr/query/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def get_results(self, **kwargs) -> List[dict]:
Returns:
Solr response documents as a list of dictionaries.
"""

# TODO: can we store the result cache and only retrieve
# if query options have changed?
# For now, always query.
Expand All @@ -83,9 +82,14 @@ def get_results(self, **kwargs) -> List[dict]:
self._result_cache = self.solr.query(**query_opts)
# if there is a query error, result will not be set
if self._result_cache:
return [doc.as_dict() for doc in self._result_cache.docs]
return [self.get_result_document(doc) for doc in self._result_cache.docs]
return []

def get_result_document(self, doc):
"""Method to transform document results. Default behavior is to
convert from attrdict to dict."""
return doc.as_dict()

def _set_highlighting_opts(self, query_opts: Dict) -> None:
"""Configure highlighting attributes on query_opts. Modifies
dictionary directly."""
Expand Down

0 comments on commit 89de6a8

Please sign in to comment.