mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-03-16 22:20:31 +00:00
Updated to use changed get_identifier method
This commit is contained in:
parent
bac4705998
commit
abd5920645
3 changed files with 12 additions and 13 deletions
3
AUTHORS
3
AUTHORS
|
|
@ -8,4 +8,5 @@ Thanks to:
|
|||
* Trapeze Media <http://www.trapeze.com/> 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.
|
||||
* Jannis Leidel for setting up the code base for pip, easy_install and PyPI.
|
||||
* Erik Aigner for the initial patch to get_identifier changes.
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue