diff --git a/spirit/core/conf/defaults.py b/spirit/core/conf/defaults.py index 588a943b6..e1fac9560 100644 --- a/spirit/core/conf/defaults.py +++ b/spirit/core/conf/defaults.py @@ -202,6 +202,12 @@ #: Latin, Greek, and Cyrillic charsets ST_EXTENDED_FONT = False +#: This enables search on Asian languages, +#: and across word boundaries. It'll increase the index size. +#: Changing this setting requires re-building the +#: search index by running `python manage.py rebuild_index` +ST_NGRAM_SEARCH = False + # Tests helper ST_TESTS_RATELIMIT_NEVER_EXPIRE = False diff --git a/spirit/extra/project_template/project_name/settings/prod.py b/spirit/extra/project_template/project_name/settings/prod.py index 9d5fa1ec0..30654c9dc 100644 --- a/spirit/extra/project_template/project_name/settings/prod.py +++ b/spirit/extra/project_template/project_name/settings/prod.py @@ -125,3 +125,7 @@ # https://spirit.readthedocs.io/en/latest/settings.html#spirit.core.conf.defaults.ST_SITE_URL ST_SITE_URL = 'https://example.com/' + +# If using elasticsearch, this fixes: +# https://github.com/django-haystack/django-haystack/issues/1057 +ELASTICSEARCH_DEFAULT_NGRAM_SEARCH_ANALYZER = 'standard' diff --git a/spirit/search/search_indexes.py b/spirit/search/search_indexes.py index 504a37691..aed4d0ed6 100644 --- a/spirit/search/search_indexes.py +++ b/spirit/search/search_indexes.py @@ -27,9 +27,14 @@ def convert(self, value): return bool(value) +TEXT_FIELD = indexes.CharField +if settings.ST_NGRAM_SEARCH: + TEXT_FIELD = indexes.NgramField + + class TopicIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True, stored=False) + text = TEXT_FIELD(document=True, use_template=True, stored=False) category_id = indexes.IntegerField(model_attr='category_id', stored=False) is_removed = BooleanField(stored=False)