From abd59206458bd80d8ce1c15fd657ea42be5c6413 Mon Sep 17 00:00:00 2001 From: David Sauve Date: Mon, 9 Nov 2009 20:27:46 -0500 Subject: [PATCH] Updated to use changed get_identifier method --- AUTHORS | 3 ++- tests/xapian_tests/tests/xapian_backend.py | 10 +++++----- xapian_backend.py | 12 +++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5c99d9f..8149866 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,4 +8,5 @@ Thanks to: * Trapeze Media for providing the time and resources to complete this project as well as Q&A. * Supreet Sethi for suggestions regarding morphologic date comparisons and for fixing NOT query expressions. * Joshua Jonah for changes to highlighting logic to avoid reserved words. - * Jannis Leidel for setting up the code base for pip, easy_install and PyPI. \ No newline at end of file + * Jannis Leidel for setting up the code base for pip, easy_install and PyPI. + * Erik Aigner for the initial patch to get_identifier changes. \ No newline at end of file diff --git a/tests/xapian_tests/tests/xapian_backend.py b/tests/xapian_tests/tests/xapian_backend.py index 95d336f..80fa3e1 100644 --- a/tests/xapian_tests/tests/xapian_backend.py +++ b/tests/xapian_tests/tests/xapian_backend.py @@ -140,9 +140,9 @@ class XapianSearchBackendTestCase(TestCase): self.assertEqual(len(self.xapian_search('')), 3) self.assertEqual([dict(doc) for doc in self.xapian_search('')], [ - {'flag': u't', 'name': u'david1', 'text': u'Indexed!\n1', 'sites': u"['1', '2', '3']", 'pub_date': u'20090224000000', 'value': u'000000000005', 'id': u'tests.xapianmockmodel.1', 'slug': u'http://example.com/1', 'popularity': '\xca\x84'}, - {'flag': u'f', 'name': u'david2', 'text': u'Indexed!\n2', 'sites': u"['2', '4', '6']", 'pub_date': u'20090223000000', 'value': u'000000000010', 'id': u'tests.xapianmockmodel.2', 'slug': u'http://example.com/2', 'popularity': '\xb4`'}, - {'flag': u't', 'name': u'david3', 'text': u'Indexed!\n3', 'sites': u"['3', '6', '9']", 'pub_date': u'20090222000000', 'value': u'000000000015', 'id': u'tests.xapianmockmodel.3', 'slug': u'http://example.com/3', 'popularity': '\xcb\x98'} + {'flag': u't', 'name': u'david1', 'text': u'Indexed!\n1', 'sites': u"['1', '2', '3']", 'pub_date': u'20090224000000', 'value': u'000000000005', 'id': u'tests.xapianmockmodel.1', 'slug': u'http://example.com/1', 'popularity': '\xca\x84', 'django_id': u'1', 'django_ct': u'tests.xapianmockmodel'}, + {'flag': u'f', 'name': u'david2', 'text': u'Indexed!\n2', 'sites': u"['2', '4', '6']", 'pub_date': u'20090223000000', 'value': u'000000000010', 'id': u'tests.xapianmockmodel.2', 'slug': u'http://example.com/2', 'popularity': '\xb4`', 'django_id': u'2', 'django_ct': u'tests.xapianmockmodel'}, + {'flag': u't', 'name': u'david3', 'text': u'Indexed!\n3', 'sites': u"['3', '6', '9']", 'pub_date': u'20090222000000', 'value': u'000000000015', 'id': u'tests.xapianmockmodel.3', 'slug': u'http://example.com/3', 'popularity': '\xcb\x98', 'django_id': u'3', 'django_ct': u'tests.xapianmockmodel'} ]) def test_remove(self): @@ -152,8 +152,8 @@ class XapianSearchBackendTestCase(TestCase): self.sb.remove(self.sample_objs[0]) self.assertEqual(len(self.xapian_search('')), 2) self.assertEqual([dict(doc) for doc in self.xapian_search('')], [ - {'flag': u'f', 'name': u'david2', 'text': u'Indexed!\n2', 'sites': u"['2', '4', '6']", 'pub_date': u'20090223000000', 'value': u'000000000010', 'id': u'tests.xapianmockmodel.2', 'slug': u'http://example.com/2', 'popularity': '\xb4`'}, - {'flag': u't', 'name': u'david3', 'text': u'Indexed!\n3', 'sites': u"['3', '6', '9']", 'pub_date': u'20090222000000', 'value': u'000000000015', 'id': u'tests.xapianmockmodel.3', 'slug': u'http://example.com/3', 'popularity': '\xcb\x98'} + {'flag': u'f', 'name': u'david2', 'text': u'Indexed!\n2', 'sites': u"['2', '4', '6']", 'pub_date': u'20090223000000', 'value': u'000000000010', 'id': u'tests.xapianmockmodel.2', 'slug': u'http://example.com/2', 'popularity': '\xb4`', 'django_id': u'2', 'django_ct': u'tests.xapianmockmodel'}, + {'flag': u't', 'name': u'david3', 'text': u'Indexed!\n3', 'sites': u"['3', '6', '9']", 'pub_date': u'20090222000000', 'value': u'000000000015', 'id': u'tests.xapianmockmodel.3', 'slug': u'http://example.com/3', 'popularity': '\xcb\x98', 'django_id': u'3', 'django_ct': u'tests.xapianmockmodel'} ]) def test_clear(self): diff --git a/xapian_backend.py b/xapian_backend.py index 2211d05..6effaae 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -33,6 +33,7 @@ from haystack.backends import BaseSearchBackend, BaseSearchQuery, log_query from haystack.exceptions import MissingDependency from haystack.fields import DateField, DateTimeField, IntegerField, FloatField, BooleanField, MultiValueField from haystack.models import SearchResult +from haystack.utils import get_identifier try: import xapian @@ -159,9 +160,6 @@ class SearchBackend(BaseSearchBackend): self.stemmer = xapian.Stem(stemming_language) - def get_identifier(self, obj_or_string): - return DOCUMENT_ID_TERM_PREFIX + super(SearchBackend, self).get_identifier(obj_or_string) - def update(self, index, iterable): """ Updates the `index` with any objects in `iterable` by adding/updating @@ -204,7 +202,7 @@ class SearchBackend(BaseSearchBackend): for obj in iterable: document = xapian.Document() term_generator = self._term_generator(database, document) - document_id = self.get_identifier(obj) + document_id = DOCUMENT_ID_TERM_PREFIX + get_identifier(obj) data = index.prepare(obj) for field in self.schema: @@ -238,7 +236,7 @@ class SearchBackend(BaseSearchBackend): should be unique to this object. """ database = self._database(writable=True) - database.delete_document(self.get_identifier(obj)) + database.delete_document(DOCUMENT_ID_TERM_PREFIX + get_identifier(obj)) def clear(self, models=[]): """ @@ -434,7 +432,7 @@ class SearchBackend(BaseSearchBackend): Finally, processes the resulting matches and returns. """ database = self._database() - query = xapian.Query(self.get_identifier(model_instance)) + query = xapian.Query(DOCUMENT_ID_TERM_PREFIX + get_identifier(model_instance)) enquire = self._enquire(database, query) rset = xapian.RSet() for match in enquire.get_mset(0, DEFAULT_MAX_RESULTS): @@ -443,7 +441,7 @@ class SearchBackend(BaseSearchBackend): [expand.term for expand in enquire.get_eset(DEFAULT_MAX_RESULTS, rset, XHExpandDecider())] ) query = xapian.Query( - xapian.Query.OP_AND_NOT, [query, self.get_identifier(model_instance)] + xapian.Query.OP_AND_NOT, [query, DOCUMENT_ID_TERM_PREFIX + get_identifier(model_instance)] ) narrow_queries = None if limit_to_registered_models: