Fix search suggest to respect content type filtering in Guide and other sections #1186
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 #346 where the search field in the Guide section displayed "Search the Guide..." placeholder but auto-suggest dropdown showed results from all content types (API docs, wiki, extensions, news) instead of only guide content.
Problem
When users typed in the search field on guide pages, they would see suggestions for API classes, wiki pages, and other content types, which was confusing since the placeholder text suggested they were searching within the guide only.
Root Cause
The
searchSuggestJavaScript function was calling the/search/suggestendpoint without including thetypeparameter, even though:SearchFormwidget correctly settype => 'guide'GuideControllerhad$searchScope = SearchActiveRecord::SEARCH_GUIDESearchActiveRecord::searchAsYouTypemethod didn't accept or use a type parameter for filteringSolution
Implemented end-to-end type-aware filtering for search suggestions:
Backend Changes
$typeparameter validation and pass-through to search method$typeparameter and filtering logic:type='guide'→ Onlyguide-sectionresultstype='api'→ Onlyapi-typeresultstype='wiki'→ Onlywikiresultstype=null→ All content types (unchanged behavior)Frontend Changes
yiiSearchTypeJavaScript variable when search type is availabletypeparameter in AJAX requests to suggest endpointResult
Testing
Verified with unit tests that:
The fix makes search behavior consistent with user expectations based on the placeholder text and current page context.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
asset-packagist.org/usr/bin/php8.3 -n -c /tmp/UaeGBa /usr/bin/composer update --no-dev(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.