In the previous few article we have discuss about writing page model.If you have not gone through it you see through this link writing own page model.In which i have discuss one of the most important think while writing which is Search.In this article we learn more about Search more.
Wagtail provides a comprehensive and extensible search interface. In addition, it provides ways to promote search results through "Editor's Picks". Wagtail also collects simple statistics on queries made through the search interface.
Search has basically three major part:-
To make a model searchable, you'll need to add it into the search index. All pages, images and documents are indexed , so you can start searching them right away.
You can basically use following three operation in Indexing:-
Wagtail provides an API for performing search queries on your models. You can also perform search queries on Django QuerySets.
Wagtail provides a shortcut for searching pages: the .search() QuerySet method. You can call this on any PageQuerySet.
# Search future EventPages
>>> from wagtail.core.models import EventPage
>>> EventPage.objects.filter(date__gt=timezone.now()).search("Hello world!")
All other methods of PageQuerySet can be used with search()
# Search all live EventPages that are under the events index
[<EventPage: Event 1>, <EventPage: Event 2>]
Wagtail provides three backends for storing the search index and performing search queries: Elasticsearch, the database, and PostgreSQL (Django >=1.10 required).
It's also possible to roll your own search backend