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
searchSuggest
JavaScript function was calling the/search/suggest
endpoint without including thetype
parameter, even though:SearchForm
widget correctly settype => 'guide'
GuideController
had$searchScope = SearchActiveRecord::SEARCH_GUIDE
SearchActiveRecord::searchAsYouType
method didn't accept or use a type parameter for filteringSolution
Implemented end-to-end type-aware filtering for search suggestions:
Backend Changes
$type
parameter validation and pass-through to search method$type
parameter and filtering logic:type='guide'
→ Onlyguide-section
resultstype='api'
→ Onlyapi-type
resultstype='wiki'
→ Onlywiki
resultstype=null
→ All content types (unchanged behavior)Frontend Changes
yiiSearchType
JavaScript variable when search type is availabletype
parameter 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.