Skip to content

Commit

Permalink
Support search on Asian languages
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Jan 28, 2022
1 parent 01e5799 commit 13f338c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spirit/core/conf/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spirit/extra/project_template/project_name/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 6 additions & 1 deletion spirit/search/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 13f338c

Please sign in to comment.