searching.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ``wagtailcrx/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. .. deprecated:: 0.25
  29. The following behavior and the ``search_db_*`` options were removed in 0.25.
  30. Use the `Wagtail search parameters <https://docs.wagtail.org/en/stable/reference/contrib/searchpromotions.html#module-wagtail.contrib.search_promotions>`_ instead.
  31. If using the ``wagtail.search.backends.db`` backend (removed in Wagtail 3.0), only page Title and Search Description
  32. fields are searched upon. This is due to a limitation in the DatabaseSearch backend;
  33. other backends such as PostgreSQL and Elasticsearch will search on additional specific fields
  34. such as body, article captions, etc. To enable more specific searching while still using the
  35. database backend, the specific models can be flagged for inclusion in search by setting
  36. ``search_db_include = True`` on the page model. Note that this must be set on every type of page
  37. model you wish to include in search. When setting this flag, search is performed independently on
  38. each page type, and the results are combined. So you may want to also specify ``search_db_boost`` (int)
  39. to control the order in which the pages are searched. Pages with a higher ``search_db_boost``
  40. are searched first, and results are shown higher in the list. For example::
  41. class Article(CoderedArticlePage):
  42. search_db_include = True
  43. search_db_boost = 10
  44. ...
  45. class WebPage(CoderedWebPage):
  46. search_db_include = True
  47. search_db_boost = 9
  48. ...
  49. class FormPage(CoderedFormPage):
  50. ...
  51. In this example, Article search results will be shown before WebPage results when using the
  52. DatabaseSearch backend. FormPage results will not be shown at all, due to the absence
  53. ``search_db_include``. If no models have ``search_db_include = True``, All CoderedPages
  54. will be searched by title and description. When using any search backend other than database,
  55. ``search_db_*`` variables are ignored.