diff --git a/tests/xapian_tests/tests/xapian_backend.py b/tests/xapian_tests/tests/xapian_backend.py index e21685e..457f14f 100644 --- a/tests/xapian_tests/tests/xapian_backend.py +++ b/tests/xapian_tests/tests/xapian_backend.py @@ -8,7 +8,6 @@ import xapian from django.conf import settings from django.db import models -from django.utils.encoding import force_unicode from django.test import TestCase from haystack import indexes, sites @@ -117,7 +116,6 @@ class XapianSearchBackendTestCase(TestCase): def test_update(self): self.sb.update(self.msi, self.sample_objs) - self.sb.update(self.msi, self.sample_objs) # Duplicates should be updated, not appended -- http://github.com/notanumber/xapian-haystack/issues/#issue/6 self.assertEqual(len(self.xapian_search('')), 3) self.assertEqual([dict(doc) for doc in self.xapian_search('')], [ @@ -126,6 +124,12 @@ class XapianSearchBackendTestCase(TestCase): {'flag': u'true', '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_duplicate_update(self): + self.sb.update(self.msi, self.sample_objs) + self.sb.update(self.msi, self.sample_objs) # Duplicates should be updated, not appended -- http://github.com/notanumber/xapian-haystack/issues/#issue/6 + + self.assertEqual(len(self.xapian_search('')), 3) + def test_remove(self): self.sb.update(self.msi, self.sample_objs) self.assertEqual(len(self.xapian_search('')), 3) @@ -295,18 +299,7 @@ class XapianSearchBackendTestCase(TestCase): # results = self.sb.more_like_this(self.sample_objs[0], additional_query_string='david3') # self.assertEqual(results['hits'], 1) # self.assertEqual([result.pk for result in results['results']], [3]) - - # def test_document_count(self): - # self.sb.update(self.msi, self.sample_objs) - # self.assertEqual(self.sb.document_count(), 3) - - # def test_delete_index(self): - # self.sb.update(self.msi, self.sample_objs) - # self.assert_(self.sb.document_count() > 0) - # - # self.sb.delete_index() - # self.assertRaises(InvalidIndexError, self.sb.document_count) - + # def test_order_by(self): # self.sb.update(self.msi, self.sample_objs) # diff --git a/xapian_backend.py b/xapian_backend.py index 2e8243d..eb9acff 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -17,7 +17,7 @@ from django.core.exceptions import ImproperlyConfigured from django.utils.encoding import smart_unicode, force_unicode from haystack.backends import BaseSearchBackend, BaseSearchQuery, SearchNode, log_query -from haystack.exceptions import MissingDependency, HaystackError +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 @@ -309,15 +309,6 @@ class SearchBackend(BaseSearchBackend): 'spelling_suggestion': spelling_suggestion, } - def delete_index(self): - """ - Delete the index. - - This removes all indexes files and the `HAYSTACK_XAPIAN_PATH` folder. - """ - if os.path.exists(settings.HAYSTACK_XAPIAN_PATH): - shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH) - def more_like_this(self, model_instance, additional_query_string=None, start_offset=0, end_offset=None, limit_to_registered_models=True, **kwargs): @@ -613,7 +604,7 @@ class SearchBackend(BaseSearchBackend): database.set_metadata('content', pickle.dumps(self.content_field_name, pickle.HIGHEST_PROTOCOL)) else: database = xapian.Database(settings.HAYSTACK_XAPIAN_PATH) - + self.schema = pickle.loads(database.get_metadata('schema')) self.content_field_name = pickle.loads(database.get_metadata('content'))