Permalink
Browse files

Merge branch 'aptivate-extra_options'

  • Loading branch information...
2 parents f49c86d + 8f29607 commit 7528ec4b01fc9e2aea02a3938d8df69eb17f2937 @tow committed Oct 28, 2015
Showing with 25 additions and 2 deletions.
  1. +25 −2 sunburnt/search.py
View
27 sunburnt/search.py
@@ -375,8 +375,9 @@ def add_boost(self, kwargs, boost_score):
class BaseSearch(object):
"""Base class for common search options management"""
option_modules = ('query_obj', 'filter_obj', 'paginator',
- 'more_like_this', 'highlighter', 'faceter', 'facet_ranger',
- 'sorter', 'facet_querier', 'field_limiter',)
+ 'more_like_this', 'highlighter', 'faceter',
+ 'facet_ranger', 'sorter', 'facet_querier',
+ 'field_limiter', 'extra')
result_constructor = dict
@@ -390,6 +391,7 @@ def _init_common_modules(self):
self.sorter = SortOptions(self.schema)
self.field_limiter = FieldLimitOptions(self.schema)
self.facet_querier = FacetQueryOptions(self.schema)
+ self.extra = ExtraOptions(self.schema)
def clone(self):
return self.__class__(interface=self.interface, original=self)
@@ -481,6 +483,11 @@ def field_limit(self, fields=None, score=False, all_fields=False):
newself.field_limiter.update(fields, score, all_fields)
return newself
+ def add_extra(self, **kwargs):
+ newself = self.clone()
+ newself.extra.update(kwargs)
+ return newself
+
def options(self):
options = {}
for option_module in self.option_modules:
@@ -1156,6 +1163,22 @@ def options(self):
else:
return {}
+
+class ExtraOptions(Options):
+ def __init__(self, schema, original=None):
+ self.schema = schema
+ if original is None:
+ self.option_dict = {}
+ else:
+ self.option_dict = original.option_dict.copy()
+
+ def update(self, extra_options):
+ self.option_dict.update(extra_options)
+
+ def options(self):
+ return self.option_dict
+
+
def params_from_dict(**kwargs):
utf8_params = []
for k, vs in kwargs.items():

0 comments on commit 7528ec4

Please sign in to comment.