searching.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Searching
  2. =========
  3. A search page is available by default at the ``/search/`` URL, which can be customized in the
  4. ``urls.py`` file in your project. To enable a search bar in the navigation bar, check
  5. Settings > Layout > Search box. Search results are paginated; to specify the number of results
  6. per page, edit the value in Settings > General > Search Settings.
  7. Search result formatting
  8. ------------------------
  9. Each search result is rendered using the template at ``coderedcms/pages/search_result.html``.
  10. The template can be overridden per model with the ``search_template`` attribute.
  11. Search result filtering
  12. -----------------------
  13. To enable additional filtering by page type, add ``search_filterable = True`` to the page model.
  14. The ``search_name`` and ``search_name_plural`` fields are then used to display the labels for
  15. these filters (defaults to ``verbose_name`` and ``verbose_name_plural`` if not specified).
  16. For example, to enable search filtering by Blog or by Products in addition to All Results::
  17. class BlogPage(CoderedArticlePage):
  18. search_filterable = True
  19. search_name = 'Blog Post'
  20. search_name_plural = 'Blog'
  21. class Product(CoderedWebPage):
  22. search_filterable = True
  23. search_name = 'Product'
  24. search_name_plural = 'Products'
  25. Would enable the following filter options on the search page: All Results, Blog, Products.
  26. Search fields
  27. -------------
  28. If using the Wagtail DatabaseSearch backend (default), only page Title and Search Description
  29. fields are searched upon. This is due to a limitation in the DatabaseSearch backend;
  30. other backends such as PostgreSQL and Elasticsearch will search on additional specific fields
  31. such as body, article captions, etc. To enable more specific searching while still using the
  32. database backend, the specific models can be flagged for inclusion in search by setting
  33. ``search_db_include = True`` on the page model. Note that this must be set on every type of page
  34. model you wish to include in search. When setting this flag, search is performed independently on
  35. each page type, and the results are combined. So you may want to also specify ``search_db_boost`` (int)
  36. to control the order in which the pages are searched. Pages with a higher ``search_db_boost``
  37. are searched first, and results are shown higher in the list. For example::
  38. class Article(CoderedArticlePage):
  39. search_db_include = True
  40. search_db_boost = 10
  41. ...
  42. class WebPage(CoderedWebPage):
  43. search_db_include = True
  44. search_db_boost = 9
  45. ...
  46. class FormPage(CoderedFormPage):
  47. ...
  48. In this example, Article search results will be shown before WebPage results when using the
  49. DatabaseSearch backend. FormPage results will not be shown at all, due to the absence
  50. ``search_db_include``. If no models have ``search_db_include = True``, All CoderedPages
  51. will be searched by title and description. When using any search backend other than database,
  52. ``search_db_*`` variables are ignored.