From 99dc011a2560f26e30a691f65df90f46ae78976e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20C=2E=20Leit=C3=A3o?= Date: Sat, 17 May 2014 13:19:17 +0200 Subject: [PATCH] Refactored _filter_in query constructor. --- xapian_backend.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/xapian_backend.py b/xapian_backend.py index b057da8..c138513 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -1092,27 +1092,16 @@ class XapianSearchQuery(BaseSearchQuery): def _filter_in(self, term_list, field_name, field_type, is_not): """ - Private method that returns a xapian.Query that searches for any term - of `value_list` in a specified `field`. + Returns a query that matches exactly ANY term in term_list. - Required arguments: - ``term_list`` -- The terms to search for - ``field`` -- The field to search - ``is_not`` -- Invert the search results - - Returns: - A xapian.Query + Notice that: + A in {B,C} <=> (A = B or A = C) + ~(A in {B,C}) <=> ~(A = B or A = C) + Because OP_AND_NOT(C, D) <=> (C and ~D), then D=(A in {B,C}) requires `is_not=False`. """ - query_list = [] - for term in term_list: - if ' ' in term: - query_list.append( - self._phrase_query(term.split(), field_name) - ) - else: - query_list.append( - self._term_query(term, field_name, field_type) - ) + query_list = [self._filter_exact(term, field_name, field_type, is_not=False) + for term in term_list] + if is_not: return xapian.Query(xapian.Query.OP_AND_NOT, self._all_query(), xapian.Query(xapian.Query.OP_OR, query_list))