Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 29, 2025

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 the type parameter, even though:

  • The SearchForm widget correctly set type => 'guide'
  • The GuideController had $searchScope = SearchActiveRecord::SEARCH_GUIDE
  • The backend SearchActiveRecord::searchAsYouType method didn't accept or use a type parameter for filtering

Solution

Implemented end-to-end type-aware filtering for search suggestions:

Backend Changes

  • SearchController::actionSuggest: Added $type parameter validation and pass-through to search method
  • SearchActiveRecord::searchAsYouType: Added $type parameter and filtering logic:
    • type='guide' → Only guide-section results
    • type='api' → Only api-type results
    • type='wiki' → Only wiki results
    • type=null → All content types (unchanged behavior)

Frontend Changes

  • _searchForm.php: Register yiiSearchType JavaScript variable when search type is available
  • search.js: Include type parameter in AJAX requests to suggest endpoint

Result

  • Guide page search suggestions now only show guide content
  • API page search suggestions only show API content
  • Other sections are similarly scoped to their content type
  • Global search continues to show all content types
  • Full search (pressing Enter) behavior unchanged
  • OpenSearch functionality unaffected

Testing

Verified with unit tests that:

  • Type parameter validation works correctly
  • JavaScript URL building includes type parameter
  • Type filtering logic returns expected content types
  • Integration workflow functions end-to-end

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
    • Triggering command: /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.

Copilot AI and others added 2 commits July 29, 2025 11:12
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copilot AI changed the title [WIP] @yiisoft-contrib/yiiframework.com/issues/346 Fix search suggest to respect content type filtering in Guide and other sections Jul 29, 2025
Copilot AI requested a review from samdark July 29, 2025 11:19
Copilot finished work on behalf of samdark July 29, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong placeholder text for the search field in Guide

2 participants