Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make model filter for simple backend work

Adds Stefan Wehrmeyer to AUTHORS for patch
  • Loading branch information...
commit ff5064b16ed430e3e6482f460c240f057531d0e7 1 parent 0e8bd20
@stefanw stefanw authored
View
1  AUTHORS
@@ -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
View
6 haystack/backends/simple_backend.py
@@ -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:
View
5 tests/simple_tests/tests/simple_backend.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.