diff --git a/tests/xapian_tests/tests/test_interface.py b/tests/xapian_tests/tests/test_interface.py index 8dcb1d8..1847c1c 100644 --- a/tests/xapian_tests/tests/test_interface.py +++ b/tests/xapian_tests/tests/test_interface.py @@ -71,6 +71,12 @@ def test_content_search(self): # documents with "medium" AND "this" have higher score self.assertEqual(pks(result)[:4], [1, 4, 7, 10]) + def test_content_search2(self): + # content should only search the document, not all fields. + result = self.queryset.filter(content='summary') + self.assertEqual(pks(result), []) + + def test_field_search(self): self.assertEqual(pks(self.queryset.filter(name__contains='8')), [4]) self.assertEqual(pks(self.queryset.filter(type_name='book')), diff --git a/xapian_backend.py b/xapian_backend.py index 5438e3c..4f640ee 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -1292,10 +1292,9 @@ def _query_from_term(self, term, field_name, filter_type, is_not): # It it is an AutoQuery, it has no filters # or others, thus we short-circuit the procedure. if isinstance(term, AutoQuery): - if field_name != 'content': - query = '%s:%s' % (field_name, term.prepare(self)) - else: - query = term.prepare(self) + if field_name == 'content': + field_name = self.backend.content_field_name + query = '%s:%s' % (field_name, term.prepare(self)) return [self.backend.parse_query(query)] query_list = [] @@ -1304,10 +1303,10 @@ def _query_from_term(self, term, field_name, filter_type, is_not): term = list(term) if field_name == 'content': - # content is the generic search: - # force no field_name search + # content is the document search: + # adjust field_name to point to the document field # and the field_type to be 'text'. - field_name = None + field_name = self.backend.content_field_name field_type = 'text' # we don't know what is the type(term), so we parse it.