The first step: Install the full-text retrieval framework django-haystack
pip3 install django-haystack
Step 2: Install search engine
pip3 install whoosh
Step Three: Configure the settings app
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'haystack' #全文检索框架
'movie.apps.MovieConfig',
]
Configuration # text retrieval frame
HAYSTACK_CONNECTIONS = {
'default': {
# engine using whoosh
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
# index file path (no established manually, automatically build)
'the PATH': the os.path.join (base_dir, 'whoosh_index'),
}
}
# when to add, modify, delete data, automatically generates the index
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
Article # specified number of search results per page
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 1
step 4:
definition of the class index
# Class definitions index
from the Indexes Import haystack
# import your model classes
from movie.models Import Movie
# specified index data for a certain class of
# index class name format: Index model class name +
class MovieIndex (indexes.SearchIndex, indexes.Indexable):
# designated index field use_template = True indicates which fields in accordance with the table index file is a file in
text = indexes.CharField (document = True, use_template = True) use_template = True template file described in construction of the index file
DEF get_model (Self):
# return your model class
return Movie
# indexed data
DEF index_queryset (Self, a using = None):
return self.get_model () objects.all ().
step five: index file
to build the index file in the template file,
Step 6:
write in what field to search in the index file goodssku_text.txt file
Step 7:
Step eight: Use full-text search
Step 9: Configure URL
Step 10
Step 11, change the word way: instead stuttered word