Exclude singleton pages from search results
This commit is contained in:
parent
27a5d8891b
commit
c09669693f
1 changed files with 5 additions and 3 deletions
|
@ -10,8 +10,7 @@ from wagtail.models import Page
|
||||||
from wagtail.search.utils import parse_query_string
|
from wagtail.search.utils import parse_query_string
|
||||||
|
|
||||||
from website.common.models import BaseContentPage
|
from website.common.models import BaseContentPage
|
||||||
from website.common.utils import TocEntry
|
from website.common.utils import TocEntry, get_page_models
|
||||||
from website.home.models import HomePage
|
|
||||||
|
|
||||||
from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer
|
from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer
|
||||||
|
|
||||||
|
@ -22,6 +21,9 @@ class SearchPage(RoutablePageMixin, BaseContentPage):
|
||||||
parent_page_types = ["home.HomePage"]
|
parent_page_types = ["home.HomePage"]
|
||||||
PAGE_SIZE = 15
|
PAGE_SIZE = 15
|
||||||
|
|
||||||
|
# Exclude singleton pages from search results
|
||||||
|
EXCLUDED_PAGE_TYPES = {page for page in get_page_models() if page.max_count == 1}
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def show_reading_time(self) -> bool:
|
def show_reading_time(self) -> bool:
|
||||||
return False
|
return False
|
||||||
|
@ -65,7 +67,7 @@ class SearchPage(RoutablePageMixin, BaseContentPage):
|
||||||
pages = (
|
pages = (
|
||||||
Page.objects.live()
|
Page.objects.live()
|
||||||
.public()
|
.public()
|
||||||
.not_type(self.__class__, HomePage)
|
.not_type(self.__class__, *self.EXCLUDED_PAGE_TYPES)
|
||||||
.search(query, order_by_relevance=True)
|
.search(query, order_by_relevance=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue