Skip to content
Browse files

Enable setting result constructor before calling execute()

  • Loading branch information...
1 parent ff5d12a commit b3d703685a3a44bbc1c550b42dd77ebd2d3585fd David Evans committed Mar 15, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −1 sunburnt/search.py
View
12 sunburnt/search.py
@@ -364,6 +364,8 @@ class BaseSearch(object):
'more_like_this', 'highlighter', 'faceter',
'sorter', 'facet_querier', 'field_limiter',)
+ result_constructor = dict
+
def _init_common_modules(self):
self.query_obj = LuceneQuery(self.schema, u'q')
self.filter_obj = LuceneQuery(self.schema, u'fq')
@@ -466,6 +468,11 @@ def options(self):
# Next line is for pre-2.6.5 python
return dict((k.encode('utf8'), v) for k, v in options.items())
+ def results_as(self, constructor):
+ newself = self.clone()
+ newself.result_constructor = constructor
+ return newself
+
def transform_result(self, result, constructor):
if constructor is not dict:
result.result.docs = [constructor(**d) for d in result.result.docs]
@@ -588,14 +595,17 @@ def __init__(self, interface, original=None):
else:
for opt in self.option_modules:
setattr(self, opt, getattr(original, opt).clone())
+ self.result_constructor = original.result_constructor
def options(self):
options = super(SolrSearch, self).options()
if 'q' not in options:
options['q'] = '*:*' # search everything
return options
- def execute(self, constructor=dict):
+ def execute(self, constructor=None):
+ if constructor is None:
+ constructor = self.result_constructor
result = self.interface.search(**self.options())
return self.transform_result(result, constructor)

0 comments on commit b3d7036

Please sign in to comment.
Something went wrong with that request. Please try again.