From 051fe7ddd43d99ad205953e0cad5f18fc641645c Mon Sep 17 00:00:00 2001 From: David Sauve Date: Fri, 14 Aug 2009 18:54:46 -0400 Subject: [PATCH] Fixed bug in 'mlt'. Was using not allowing additional_query_string, start_offset, and end_offset params --- xapian_backend.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xapian_backend.py b/xapian_backend.py index e747b08..017e0e7 100644 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -366,7 +366,8 @@ class SearchBackend(BaseSearchBackend): return 0 return database.get_doccount() - def more_like_this(self, model_instance): + def more_like_this(self, model_instance, additional_query_string=None, + start_offset=0, end_offset=DEFAULT_MAX_RESULTS, **kwargs): """ Given a model instance, returns a result set of similar documents. @@ -374,6 +375,12 @@ class SearchBackend(BaseSearchBackend): `model_instance` -- The model instance to use as a basis for retrieving similar documents. + Optional arguments: + `additional_query_string` -- An additional query string to narrow + results + `start_offset` -- The starting offset (default=0) + `end_offset` -- The ending offset (default=None) + Returns: A dictionary with the following keys: `results` -- A list of `SearchResult` @@ -402,10 +409,14 @@ class SearchBackend(BaseSearchBackend): query = xapian.Query( xapian.Query.OP_AND_NOT, [query, self.get_identifier(model_instance)] ) + if additional_query_string: + query = xapian.Query( + xapian.Query.OP_AND, [query, self._query(database, additional_query_string)] + ) enquire.set_query(query) results = [] - matches = enquire.get_mset(0, DEFAULT_MAX_RESULTS) + matches = enquire.get_mset(start_offset, end_offset) for match in matches: document = match.get_document()