Fix fallback search ordering and add search view tests#665
Open
Anayo-Anyafulu wants to merge 3 commits intowagtail:mainfrom
Open
Fix fallback search ordering and add search view tests#665Anayo-Anyafulu wants to merge 3 commits intowagtail:mainfrom
Anayo-Anyafulu wants to merge 3 commits intowagtail:mainfrom
Conversation
Page.objects.filter(id__in=page_ids) does not preserve the order of the provided ID list. This caused fallback search results to appear in database default order rather than the intended merged order. Fixed by applying explicit ordering using a Case/When expression so that the final queryset preserves the merged ID order deterministically. Pagination behavior is unchanged. Fixes wagtail#663
Cover HTTP 200 rendering, correct template usage, empty query behaviour, per-model result discovery, and fallback ordering preservation via Case/When (related to wagtail#665).
Contributor
|
Hi @Anayo-Anyafulu I found a related bug that RecipePage is missing from the hardcoded model list in the search path. Currently search/views.py imports only BlogPage, BreadPage and LocationPage whereas RecipePage is missing and is invisible from web search.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #663. Closes search app portion of #623.
Changes
Fix:
Page.objects.filter(id__in=page_ids)does not preserve the order of the provided ID list, causing fallback search results to appear in database default order instead of the intended merged order.Added
Case/Whenexpression to preserve merged ID ordering in the fallback search queryset. Pagination behaviour is unchanged.Tests: Added
bakerydemo/search/tests/test_search_view.pywith 8 tests covering:search/search_results.html)Case/WhenFollows the
WagtailPageTestCasepattern frombakerydemo/base/tests/.AI usage
I used Claude (claude.ai) to help understand the bug and navigate the codebase. The fix and tests were identified and verified by reading the source code directly.