diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b26b76ef9e..cc743cfa44 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -16,6 +16,7 @@ Changelog * Added pagination to "choose destination" view when moving pages (Nick Smith, Žan Anderle) * Added ability to annotate search results with score (Karl Hobley) * Added ability to limit access to form submissions (Mikalai Radchuk) + * Added the ability to configure the number of days search logs are kept for (Stephen Rice) * Fix: Migrations for wagtailcore and project template are now reversible (Benjamin Bach) * Fix: The default image format label text ('Full width', 'Left-aligned', 'Right-aligned') is now localised (Mikalai Radchuk) * Fix: Text on the front-end 'password required' form is now marked for translation (Janneke Janssen) diff --git a/docs/advanced_topics/settings.rst b/docs/advanced_topics/settings.rst index 6f9876545b..3dc7d9ba40 100644 --- a/docs/advanced_topics/settings.rst +++ b/docs/advanced_topics/settings.rst @@ -178,11 +178,6 @@ Search .. code-block:: python - # Override the search results template for wagtailsearch - WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html' - WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html' - - # Replace the search backend WAGTAILSEARCH_BACKENDS = { 'default': { 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch2', @@ -190,7 +185,22 @@ Search } } -The search settings customise the search results templates as well as choosing a custom backend for search. For a full explanation, see :ref:`search`. +Define a search backend. For a full explanation, see :ref:`wagtailsearch_backends`. + +.. code-block:: python + + WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html' + WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html' + +Override the templates used by the search front-end views. + +.. _wagtailsearch_hits_max_age: + +.. code-block:: python + + WAGTAILSEARCH_HITS_MAX_AGE = 14 + +Set the number of days (default 7) that search query logs are kept for; these are used to identify popular search terms for :ref:`promoted search results `. Queries older than this will be removed by the :ref:`search_garbage_collect` command. Embeds diff --git a/docs/reference/management_commands.rst b/docs/reference/management_commands.rst index 5b65c57483..49aaa42386 100644 --- a/docs/reference/management_commands.rst +++ b/docs/reference/management_commands.rst @@ -95,4 +95,4 @@ search_garbage_collect :code:`./manage.py search_garbage_collect` -Wagtail keeps a log of search queries that are popular on your website. On high traffic websites, this log may get big and you may want to clean out old search queries. This command cleans out all search query logs that are more than one week old. +Wagtail keeps a log of search queries that are popular on your website. On high traffic websites, this log may get big and you may want to clean out old search queries. This command cleans out all search query logs that are more than one week old (or a number of days configurable through the :ref:`WAGTAILSEARCH_HITS_MAX_AGE ` setting). diff --git a/docs/releases/1.7.rst b/docs/releases/1.7.rst index 71972d301d..b1e322c90a 100644 --- a/docs/releases/1.7.rst +++ b/docs/releases/1.7.rst @@ -46,6 +46,7 @@ Minor features * Added pagination to "choose destination" view when moving pages (Nick Smith, Žan Anderle) * Added ability to annotate search results with score - see :ref:`wagtailsearch_annotating_results_with_score` (Karl Hobley) * Added ability to limit access to form submissions - see :ref:`filter_form_submissions_for_user` (Mikalai Radchuk) + * Added the ability to configure the number of days search logs are kept for, through the :ref:`WAGTAILSEARCH_HITS_MAX_AGE ` setting (Stephen Rice) Bug fixes diff --git a/wagtail/wagtailsearch/models.py b/wagtail/wagtailsearch/models.py index ce9c910612..a31faf4837 100644 --- a/wagtail/wagtailsearch/models.py +++ b/wagtail/wagtailsearch/models.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals import datetime +from django.conf import settings from django.db import models from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible @@ -60,11 +61,12 @@ class QueryDailyHits(models.Model): hits = models.IntegerField(default=0) @classmethod - def garbage_collect(cls): + def garbage_collect(cls, days=None): """ - Deletes all QueryDailyHits records that are older than 7 days + Deletes all QueryDailyHits records that are older than a set number of days """ - min_date = timezone.now().date() - datetime.timedelta(days=7) + days = getattr(settings, 'WAGTAILSEARCH_HITS_MAX_AGE', 7) if days is None else days + min_date = timezone.now().date() - datetime.timedelta(days) cls.objects.filter(date__lt=min_date).delete()