From 83d10b6cc1a627604fc394adb4e8b6dcaae369ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20C=2E=20Leit=C3=A3o?= Date: Sat, 17 May 2014 13:14:43 +0200 Subject: [PATCH] Refactored _filter_startswith query constructor. Its interface is explained in the docstring. --- xapian_backend.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/xapian_backend.py b/xapian_backend.py index f2a15b1..0d827a5 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -1140,24 +1140,19 @@ class XapianSearchQuery(BaseSearchQuery): def _filter_startswith(self, term, field_name, field_type, is_not): """ - Private method that returns a xapian.Query that searches for any term - that begins with `term` in a specified `field`. - - Required arguments: - ``term`` -- The terms to search for - ``field`` -- The field to search - ``is_not`` -- Invert the search results - - Returns: - A xapian.Query + Returns a startswith query on the un-stemmed term. """ + # TODO: if field_type is of type long, we need to marsh the value. + if field_name: + query_string = '%s:%s*' % (field_name, term) + else: + query_string = '%s*' % term + + query = self.backend.parse_query(query_string) + if is_not: - return xapian.Query( - xapian.Query.OP_AND_NOT, - self._all_query(), - self.backend.parse_query('%s:%s*' % (field_name, term)), - ) - return self.backend.parse_query('%s:%s*' % (field_name, term)) + return xapian.Query(xapian.Query.OP_AND_NOT, self._all_query(), query) + return query def _phrase_query(self, term_list, field_name): """