Allow more internal data exact searches
Bump version Fix syntax error Adjust CHANGELOG.rst Add test for __exact on ID
This commit is contained in:
parent
251e924122
commit
90593c07b7
@ -5,6 +5,7 @@ xapian-haystack Changelog
|
||||
Unreleased
|
||||
----------
|
||||
|
||||
- Add DJANGO_CT, DJANGO_ID, ID to be used with '__exact' internally.
|
||||
- Dropped support for Python 3.6.
|
||||
- Fixed DatabaseLocked errors when running management commands with
|
||||
multiple workers.
|
||||
|
@ -236,6 +236,13 @@ class XapianSearchQueryTestCase(HaystackBackendTestCase, TestCase):
|
||||
self.sq.add_filter(SQ(django_ct='time'))
|
||||
self.assertExpectedQuery(self.sq.build_query(), 'CONTENTTYPEtime')
|
||||
|
||||
def test_unphrased_id(self):
|
||||
'An internal ID should NOT be phrased so one can exclude IDs.'
|
||||
self.sq.add_filter(SQ(id__in=['testing123', 'testing456']))
|
||||
expected = '(Qtesting123 OR Qtesting456)'
|
||||
self.assertExpectedQuery(
|
||||
query=self.sq.build_query(), string_or_list=expected)
|
||||
|
||||
|
||||
class SearchQueryTestCase(HaystackBackendTestCase, TestCase):
|
||||
"""
|
||||
|
@ -42,6 +42,8 @@ TERM_PREFIXES = {
|
||||
'field': 'X'
|
||||
}
|
||||
|
||||
_EXACT_SEARCHFIELDS = frozenset((DJANGO_CT, DJANGO_ID, ID))
|
||||
|
||||
MEMORY_DB_NAME = ':memory:'
|
||||
|
||||
DEFAULT_XAPIAN_FLAGS = (
|
||||
@ -1437,7 +1439,7 @@ class XapianSearchQuery(BaseSearchQuery):
|
||||
|
||||
Assumes term is not a list.
|
||||
"""
|
||||
if field_type == 'text' and field_name not in (DJANGO_CT,):
|
||||
if field_type == 'text' and field_name not in _EXACT_SEARCHFIELDS:
|
||||
term = '^ %s $' % term
|
||||
query = self._phrase_query(term.split(), field_name, field_type)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user