mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-03-16 22:20:31 +00:00
Fixed #109 - Raises InvalidIndexError when facet is not indexed.
Also added regression test.
This commit is contained in:
parent
f2b9c062a6
commit
b623ea2556
2 changed files with 22 additions and 0 deletions
|
|
@ -305,6 +305,12 @@ class XapianSearchBackendTestCase(HaystackBackendTestCase, TestCase):
|
|||
self.assertEqual(results['facets']['fields']['sites'],
|
||||
[('1', 1), ('3', 2), ('2', 2), ('4', 1), ('6', 2), ('9', 1)])
|
||||
|
||||
def test_raise_index_error_on_wrong_field(self):
|
||||
"""
|
||||
Regression test for #109.
|
||||
"""
|
||||
self.assertRaises(InvalidIndexError, self.backend.search, xapian.Query(''), facets=['dsdas'])
|
||||
|
||||
def test_date_facets(self):
|
||||
facets = {'pub_date': {'start_date': datetime.datetime(2008, 10, 26),
|
||||
'end_date': datetime.datetime(2009, 3, 26),
|
||||
|
|
|
|||
|
|
@ -366,6 +366,18 @@ class XapianSearchBackend(BaseSearchBackend):
|
|||
|
||||
return query
|
||||
|
||||
def _check_field_names(self, field_names):
|
||||
"""
|
||||
Raises InvalidIndexError if any of a field_name in field_names is
|
||||
not indexed.
|
||||
"""
|
||||
if field_names:
|
||||
for field_name in field_names:
|
||||
try:
|
||||
self.column(field_name)
|
||||
except KeyError:
|
||||
raise InvalidIndexError('Trying to use non indexed field "%s"' % field_name)
|
||||
|
||||
@log_query
|
||||
def search(self, query, sort_by=None, start_offset=0, end_offset=None,
|
||||
fields='', highlight=False, facets=None, date_facets=None,
|
||||
|
|
@ -414,6 +426,10 @@ class XapianSearchBackend(BaseSearchBackend):
|
|||
'hits': 0,
|
||||
}
|
||||
|
||||
self._check_field_names(facets)
|
||||
self._check_field_names(date_facets)
|
||||
self._check_field_names(query_facets)
|
||||
|
||||
database = self._database()
|
||||
|
||||
if result_class is None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue