Skip to content

Commit 021e453

Browse files
committed
Fixed the simple backend to not throw an exception when handed an SQ. Thanks to diegobz for the report!
1 parent 6b3407a commit 021e453

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

haystack/backends/simple_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _build_sub_query(self, search_node):
109109

110110
for child in search_node.children:
111111
if isinstance(child, SearchNode):
112-
term_list.append(self._build_query(child))
112+
term_list.append(self._build_sub_query(child))
113113
else:
114114
term_list.append(child[1])
115115

tests/simple_tests/tests/simple_backend.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
from datetime import date
2+
from django.conf import settings
23
from django.test import TestCase
34
from haystack import connections, connection_router
5+
from haystack import indexes
6+
from haystack.query import SearchQuerySet
7+
from haystack.utils.loading import UnifiedIndex
48
from core.models import MockModel
59
from core.tests.mocks import MockSearchResult
610

711

12+
class SimpleMockSearchIndex(indexes.SearchIndex):
13+
text = indexes.CharField(document=True, use_template=True)
14+
name = indexes.CharField(model_attr='author', faceted=True)
15+
pub_date = indexes.DateField(model_attr='pub_date')
16+
17+
def get_model(self):
18+
return MockModel
19+
20+
821
class SimpleSearchBackendTestCase(TestCase):
922
fixtures = ['bulk_data.json']
1023

@@ -72,3 +85,37 @@ def test_more_like_this(self):
7285

7386
# Unsupported by 'simple'. Should see empty results.
7487
self.assertEqual(self.backend.more_like_this(self.sample_objs[0])['hits'], 0)
88+
89+
90+
class LiveSimpleSearchQuerySetTestCase(TestCase):
91+
fixtures = ['bulk_data.json']
92+
93+
def setUp(self):
94+
super(LiveSimpleSearchQuerySetTestCase, self).setUp()
95+
96+
# Stow.
97+
self.old_debug = settings.DEBUG
98+
settings.DEBUG = True
99+
self.old_ui = connections['default'].get_unified_index()
100+
self.ui = UnifiedIndex()
101+
self.smmi = SimpleMockSearchIndex()
102+
self.ui.build(indexes=[self.smmi])
103+
connections['default']._index = self.ui
104+
105+
self.sample_objs = MockModel.objects.all()
106+
self.sqs = SearchQuerySet()
107+
108+
def tearDown(self):
109+
# Restore.
110+
connections['default']._index = self.old_ui
111+
settings.DEBUG = self.old_debug
112+
super(LiveSimpleSearchQuerySetTestCase, self).tearDown()
113+
114+
def test_general_queries(self):
115+
# For now, just make sure these don't throw an exception.
116+
# They won't work until the simple backend is improved.
117+
self.assertTrue(len(self.sqs.auto_query('daniel')) > 0)
118+
self.assertTrue(len(self.sqs.filter(text='index')) > 0)
119+
self.assertTrue(len(self.sqs.exclude(name='daniel')) > 0)
120+
self.assertTrue(len(self.sqs.order_by('-pub_date')) > 0)
121+

0 commit comments

Comments
 (0)