Skip to content

Commit cc0974d

Browse files
committed
chg: make backend subclassing easier
This change allows the backend build_search_kwargs to accept arbitrary extra arguments, making life easier for authors of `SearchQuery` or `SearchBackend` subclasses when they can directly pass a value which is directly supported by the backend search client.
1 parent 63a59f0 commit cc0974d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

haystack/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def build_search_kwargs(self, query_string, sort_by=None, start_offset=0, end_of
129129
narrow_queries=None, spelling_query=None,
130130
within=None, dwithin=None, distance_point=None,
131131
models=None, limit_to_registered_models=None,
132-
result_class=None):
132+
result_class=None, **extra_kwargs):
133133
# A convenience method most backends should include in order to make
134134
# extension easier.
135135
raise NotImplementedError

haystack/backends/elasticsearch_backend.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def build_search_kwargs(self, query_string, sort_by=None, start_offset=0, end_of
257257
narrow_queries=None, spelling_query=None,
258258
within=None, dwithin=None, distance_point=None,
259259
models=None, limit_to_registered_models=None,
260-
result_class=None):
260+
result_class=None, **extra_kwargs):
261261
index = haystack.connections[self.connection_alias].get_unified_index()
262262
content_field = index.document_field
263263

@@ -486,6 +486,9 @@ def build_search_kwargs(self, query_string, sort_by=None, start_offset=0, end_of
486486
else:
487487
kwargs['query']['filtered']["filter"] = {"bool": {"must": filters}}
488488

489+
if extra_kwargs:
490+
kwargs.update(extra_kwargs)
491+
489492
return kwargs
490493

491494
@log_query

haystack/backends/solr_backend.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def build_search_kwargs(self, query_string, sort_by=None, start_offset=0, end_of
147147
narrow_queries=None, spelling_query=None,
148148
within=None, dwithin=None, distance_point=None,
149149
models=None, limit_to_registered_models=None,
150-
result_class=None, stats=None):
150+
result_class=None, stats=None,
151+
**extra_kwargs):
151152
kwargs = {'fl': '* score'}
152153

153154
if fields:
@@ -283,6 +284,9 @@ def build_search_kwargs(self, query_string, sort_by=None, start_offset=0, end_of
283284
# kwargs['fl'] += ' _dist_:geodist()'
284285
pass
285286

287+
if extra_kwargs:
288+
kwargs.update(extra_kwargs)
289+
286290
return kwargs
287291

288292
def more_like_this(self, model_instance, additional_query_string=None,

0 commit comments

Comments
 (0)