Conversation
…ueries case-insensitive Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] @yiisoft-contrib/yiiframework.com/issues/1173 Need to make search case-insensitive. The search is using ElasticSearch right now.
Fix search case-sensitivity by making ElasticSearch term and prefix queries case-insensitive
Jul 28, 2025
Member
|
@copilot ensure indexed content is lowercased as well. |
…exact matching Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Contributor
Author
Fixed! Added keyword subfields with lowercase normalizer to all search model mappings and updated term queries to use these new fields. This ensures both the indexed content and queries are properly lowercased for case-insensitive exact matching. Changes in commit b42309a. |
Copilot
AI
changed the title
Fix search case-sensitivity by making ElasticSearch term and prefix queries case-insensitive
Fix search case-sensitivity by adding keyword subfields with lowercase normalizer to ElasticSearch mappings
Jul 29, 2025
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 #1173
Problem
The search functionality was case-sensitive, causing different results for queries like "Symfony" vs "symfony". This was due to ElasticSearch
termqueries being case-sensitive exact matches, and the indexed content not being normalized for case-insensitive matching.Example of the issue:
https://www.yiiframework.com/search?type=news&q=Symfonyhttps://www.yiiframework.com/search?type=news&q=symfonyThese URLs would return different search results, which is unexpected behavior for users.
Root Cause
The original implementation had two issues:
termqueries on text fields inmodels/search/SearchActiveRecord.phpEven with query-side lowercasing, the indexed content remained in original case, causing term queries to fail when searching for lowercased terms against mixed-case indexed data.
Solution
Implemented a comprehensive fix using ElasticSearch's built-in normalization capabilities:
1. Added Lowercase Normalizer
Added custom lowercase normalizer to index settings across all search models:
2. Added Keyword Subfields
Enhanced field mappings to include keyword subfields with lowercase normalizer:
3. Updated Term Queries
Modified exact match queries to use new keyword subfields:
Changes Made
SearchActiveRecord.php:
.keywordsubfieldsmb_strtolower()calls since normalization happens at index levelAll Search Models (SearchApiType, SearchExtension, SearchGuideSection, SearchNews, SearchWiki):
nameandtitlefield mappingsBenefits
Testing
The fix handles various cases correctly:
"Symfony"and"symfony"now produce identical ElasticSearch queries"ÁÉÍÓÚ"→"áéíóú")"ArrayHelper"→"arrayhelper")💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.