Skip to content

Commit 439c510

Browse files
committed
Fixed the simple backend to return SearchResult instances, not just bare model instances. Thanks to Agos for the report.
1 parent 476e860 commit 439c510

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

haystack/backends/simple_backend.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
7171
qs = model.objects.filter(reduce(lambda x, y: x|y, queries))
7272

7373
hits += len(qs)
74-
results.extend([match for match in qs])
74+
75+
for match in qs:
76+
result = SearchResult(match._meta.app_label, match._meta.module_name, match.pk, 0, **match.__dict__)
77+
# For efficiency.
78+
result._object = match.__class__
79+
result._model = match
80+
results.append(result)
7581

7682
return {
7783
'results': results,
@@ -110,7 +116,7 @@ def _build_sub_query(self, search_node):
110116

111117
for child in search_node.children:
112118
if isinstance(child, SearchNode):
113-
tarm_list.append(self._build_query(child))
119+
term_list.append(self._build_query(child))
114120
else:
115121
term_list.append(child[1])
116122

0 commit comments

Comments
 (0)