From 251e9241225b643acefe125d5d7444f8ff19f77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Szczepa=C5=84ski?= <52240554+PSzczepanski996@users.noreply.github.com> Date: Fri, 8 Jul 2022 21:52:10 +0200 Subject: [PATCH] Add ability to configure NGRAM's --- README.rst | 2 ++ xapian_backend.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 581b0d4..ebd6e87 100644 --- a/README.rst +++ b/README.rst @@ -92,6 +92,8 @@ The backend has the following optional settings: See `here `__ 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`. diff --git a/xapian_backend.py b/xapian_backend.py index fd1e2d3..d6a92bb 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -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) try: import xapian