From a27676a8509d8cf8bf723f785b8c730db1c6a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20C=2E=20Leit=C3=A3o?= Date: Sat, 17 May 2014 18:07:21 +0200 Subject: [PATCH] Fixed #111 - Removes Python error. Added test to check it works. --- tests/xapian_tests/tests/test_xapian_backend.py | 12 ++++++++++-- xapian_backend.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/xapian_tests/tests/test_xapian_backend.py b/tests/xapian_tests/tests/test_xapian_backend.py index 3b98ef6..21f5ad7 100644 --- a/tests/xapian_tests/tests/test_xapian_backend.py +++ b/tests/xapian_tests/tests/test_xapian_backend.py @@ -500,7 +500,7 @@ class XapianSearchBackendTestCase(HaystackBackendTestCase, TestCase): class LiveXapianMockSearchIndex(indexes.SearchIndex): text = indexes.CharField(document=True, use_template=True) - name = indexes.CharField(model_attr='author') + name = indexes.CharField(model_attr='author', faceted=True) pub_date = indexes.DateField(model_attr='pub_date') created = indexes.DateField() title = indexes.CharField() @@ -559,7 +559,12 @@ class LiveXapianSearchQueryTestCase(HaystackBackendTestCase, TestCase): self.sq.add_filter(SQ(created__lt=datetime.datetime(2009, 2, 12, 12, 13, 0))) self.sq.add_filter(SQ(title__gte='B')) self.sq.add_filter(SQ(id__in=[1, 2, 3])) - self.assertEqual(str(self.sq.build_query()), 'Xapian::Query(((Zwhi OR why) AND VALUE_RANGE 5 00010101000000 20090210015900 AND ( AND_NOT VALUE_RANGE 4 a david) AND ( AND_NOT VALUE_RANGE 3 20090212121300 99990101000000) AND VALUE_RANGE 7 b zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz AND (Q1 OR Q2 OR Q3)))') + self.assertEqual(str(self.sq.build_query()), + 'Xapian::Query(((Zwhi OR why) AND VALUE_RANGE 6 00010101000000 20090210015900 AND ' + '( AND_NOT VALUE_RANGE 4 a david) AND ' + '( AND_NOT VALUE_RANGE 3 20090212121300 99990101000000) AND ' + 'VALUE_RANGE 8 b zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz AND ' + '(Q1 OR Q2 OR Q3)))') def test_log_query(self): reset_search_queries() @@ -622,6 +627,9 @@ class LiveXapianSearchQuerySetTestCase(HaystackBackendTestCase, TestCase): sqs = self.sqs.result_class(None).all() self.assertTrue(isinstance(sqs[0], SearchResult)) + def test_facet(self): + self.assertEqual(len(self.sqs.facet('name').facet_counts()['fields']['name']), 3) + class XapianBoostMockSearchIndex(indexes.SearchIndex): text = indexes.CharField( diff --git a/xapian_backend.py b/xapian_backend.py index b6e488d..1196395 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -832,7 +832,7 @@ class XapianSearchBackend(BaseSearchBackend): """ facet_dict = {} - for field, query in query_facets.iteritems(): + for field, query in dict(query_facets).items(): facet_dict[field] = (query, self.search(self.parse_query(query))['hits']) return facet_dict