Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Matthias Portzel 2022-08-05 20:22:54 -04:00
commit adb15372d8
2 changed files with 8 additions and 6 deletions

View File

@ -92,6 +92,8 @@ The backend has the following optional settings:
See `here <http://xapian.org/docs/apidoc/html/classXapian_1_1QueryParser.html#ac7dc3b55b6083bd3ff98fc8b2726c8fd>`__ for
more information about the different strategies.
- ``XAPIAN_NGRAM_MIN_LENGTH``, ``XAPIAN_NGRAM_MAX_LENGTH``: options for custom configuration of ngrams (phrases) length.
- ``HAYSTACK_XAPIAN_USE_LOCKFILE``: Use a lockfile to prevent database locking errors when running management commands with multiple workers.
Defaults to `True`.

View File

@ -19,8 +19,8 @@ from haystack.inputs import AutoQuery
from haystack.models import SearchResult
from haystack.utils import get_identifier, get_model_ct
NGRAM_MIN_LENGTH = 2
NGRAM_MAX_LENGTH = 15
NGRAM_MIN_LENGTH = getattr(settings, 'XAPIAN_NGRAM_MIN_LENGTH', 2)
NGRAM_MAX_LENGTH = getattr(settings, 'XAPIAN_NGRAM_MAX_LENGTH', 15)
LONG_TERM = re.compile(b'[^\s]{239,}')
LONG_TERM_METHOD = getattr(settings, 'XAPIAN_LONG_TERM_METHOD', 'truncate')
@ -134,7 +134,7 @@ class XHValueRangeProcessor(xapian.ValueRangeProcessor):
begin = -sys.maxsize - 1
elif field_type == 'float':
begin = float('-inf')
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
begin = '00010101000000'
elif end == '*':
if field_type == 'text':
@ -143,7 +143,7 @@ class XHValueRangeProcessor(xapian.ValueRangeProcessor):
end = sys.maxsize
elif field_type == 'float':
end = float('inf')
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
end = '99990101000000'
if field_type == 'float':
@ -1616,7 +1616,7 @@ def _term_to_xapian_value(term, field_type):
value = INTEGER_FORMAT % term
elif field_type == 'float':
value = xapian.sortable_serialise(term)
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
if field_type == 'date':
# http://stackoverflow.com/a/1937636/931303 and comments
term = datetime.datetime.combine(term, datetime.time())
@ -1679,7 +1679,7 @@ def _from_xapian_value(value, field_type):
return int(value)
elif field_type == 'float':
return xapian.sortable_unserialise(value)
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
datetime_value = datetime.datetime.strptime(value, DATETIME_FORMAT)
if field_type == 'datetime':
return datetime_value