Permalink
Browse files

Make model filter for simple backend work

Adds Stefan Wehrmeyer to AUTHORS for patch
  • Loading branch information...
1 parent 0e8bd20 commit ff5064b16ed430e3e6482f460c240f057531d0e7 @stefanw stefanw committed Mar 28, 2013
Showing with 11 additions and 1 deletion.
  1. +1 −0 AUTHORS
  2. +5 −1 haystack/backends/simple_backend.py
  3. +5 −0 tests/simple_tests/tests/simple_backend.py
View
@@ -68,3 +68,4 @@ Thanks to
* Martin J. Laubach (mjl) for fixing the logic used when combining querysets
* Eric Holscher (ericholscher) for a docs fix.
* Erik Rose (erikrose) for a quick pyelasticsearch-compatibility patch
+ * Stefan Wehrmeyer (stefanw) for a simple search filter fix
@@ -45,12 +45,16 @@ def search(self, query_string, **kwargs):
hits = 0
results = []
result_class = SearchResult
+ models = connections[self.connection_alias].get_unified_index().get_indexed_models()
if kwargs.get('result_class'):
result_class = kwargs['result_class']
+ if kwargs.get('models'):
+ models = kwargs['models']
+
if query_string:
- for model in connections[self.connection_alias].get_unified_index().get_indexed_models():
+ for model in models:
if query_string == '*':
qs = model.objects.all()
else:
@@ -71,6 +71,11 @@ def test_search(self):
# Ensure that swapping the ``result_class`` works.
self.assertTrue(isinstance(self.backend.search(u'index document', result_class=MockSearchResult)['results'][0], MockSearchResult))
+ def test_filter_models(self):
+ self.backend.update(self.index, self.sample_objs)
+ self.assertEqual(self.backend.search(u'*', models=set([]))['hits'], 24)
+ self.assertEqual(self.backend.search(u'*', models=set([MockModel]))['hits'], 23)
+
def test_more_like_this(self):
self.backend.update(self.index, self.sample_objs)
self.assertEqual(self.backend.search(u'*')['hits'], 24)

0 comments on commit ff5064b

Please sign in to comment.