-
-
Couldn't load subscription status.
- Fork 855
Implement accent-insensitive search for Portuguese characters #3260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Conversation
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
- Add 'ignore_accents' config option in search settings - Implement Helper::normalizeAccents() for Portuguese accent normalization - Add Config::isIgnoreAccents() method to check configuration - Update QueryDataTable to handle accent normalization in database queries - Update CollectionDataTable to handle accent normalization in collection filtering - Add comprehensive unit tests for accent normalization - Support for Portuguese Brazilian accents: ã/á/à/â/é/ê/í/ó/ô/õ/ú/ç This allows users to search for 'simoes' and find 'Simões' when the feature is enabled. Fixes yajra#3249
- Add comprehensive ACCENT_INSENSITIVE_SEARCH.md documentation - Remove temporary test file - Includes usage examples, configuration, and performance considerations
- Add controller examples showing Eloquent, Collection, and Query Builder usage - Add Blade template example with search instructions - Add migration example with Portuguese test data - Add route and configuration examples - Demonstrates real-world usage scenarios
- Add comprehensive summary of all changes made - Document the complete implementation approach - List all modified and added files - Provide usage instructions and verification steps
- Fix missing class brace syntax error in Helper.php - Refactor getNormalizeAccentsFunction into smaller methods for better maintainability - Add proper SQL escaping and error handling - Fix keyword normalization in CollectionDataTable to avoid modification inside loop - Add comprehensive documentation and parameter validation - Preserve case sensitivity in normalizeAccents mapping - Add defensive programming checks for empty values These changes address potential security hotspots and improve code reliability.
- Replace match() expression with switch statement for PHP 7.4 compatibility - Change private methods to protected for better extensibility - Remove temporary validation files These changes should resolve CI failures related to PHP version compatibility.
- Break long lines in accent mapping for better readability - Add comments to organize accent character groups - Follow PSR-12 line length guidelines This should resolve any remaining linting issues.
- Replace dynamic SQL generation with static string literals to prevent SQL injection - Add input validation to prevent processing empty/invalid values - Add early return optimization for strings without accents - Remove unsafe addslashes() usage in favor of static SQL strings These changes should resolve SonarQube security hotspots and reliability concerns.
Quality Gate Failed Quality Gate failed
Failed conditions
2 Security Hotspots
C Reliability Rating on New Code (required ≥ A)
See analysis details on SonarQube Cloud
Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE
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.
Description
This PR implements accent-insensitive search functionality to address the issue where users cannot find results when searching without accents (e.g., searching 'simoes' to find 'Simões').
Problem
Users in Portuguese-speaking countries often don't type accents when searching, but expect to find results with accented characters. This is especially common in Brazilian Portuguese where users might search for:
Solution
Added a new configuration option
ignore_accentsthat when enabled, normalizes both search terms and data to their base characters before comparison.Changes Made
'ignore_accents' => falseto the search config indatatables.phpHelper::normalizeAccents()to convert accented characters to base charactersConfig::isIgnoreAccents()to check if the feature is enabledSupported Characters (Portuguese Brazilian)
Usage
Enable the feature in your config:
When enabled:
Testing
Database Compatibility
The feature uses appropriate database functions:
REPLACE()function cascade for each accent mappingUNACCENT()function if available, fallback toREPLACE()REPLACE()function cascadeREPLACE()function cascadeBreaking Changes
None - this is a new optional feature that is disabled by default.
Fixes #3249