Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
slowestwind wants to merge8 commits intoyajra:master
base:master
Choose a base branch
Loading
fromslowestwind:fix-issue-3249

Conversation

@slowestwind
Copy link

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:

  • 'simoes' instead of 'Simões'
  • 'joao' instead of 'João'
  • 'sao paulo' instead of 'São Paulo'

Solution

Added a new configuration optionignore_accents that when enabled, normalizes both search terms and data to their base characters before comparison.

Changes Made

  1. Configuration: Added'ignore_accents' => false to the search config indatatables.php
  2. Helper Method: CreatedHelper::normalizeAccents() to convert accented characters to base characters
  3. Config Method: AddedConfig::isIgnoreAccents() to check if the feature is enabled
  4. Query DataTable: Updated to use database functions for accent normalization in SQL queries
  5. Collection DataTable: Updated to normalize both search terms and data values
  6. Tests: Added comprehensive unit tests for the normalization function

Supported Characters (Portuguese Brazilian)

  • Ã/ã/Á/á/À/à/Â/â → a
  • É/é/Ê/ê → e
  • Í/í → i
  • Ó/ó/Ô/ô/Õ/õ → o
  • Ú/ú → u
  • Ç/ç → c

Usage

Enable the feature in your config:

'search' => ['ignore_accents' =>true,// other settings...],

When enabled:

  • Searching for 'simoes' will find 'Simões'
  • Searching for 'joao' will find 'João'
  • Searching for 'sao' will find 'São'

Testing

  • Added unit tests covering all accent mappings
  • Tests verify both individual character replacement and full text normalization
  • Backwards compatible - feature is disabled by default

Database Compatibility

The feature uses appropriate database functions:

  • MySQL:REPLACE() function cascade for each accent mapping
  • PostgreSQL:UNACCENT() function if available, fallback toREPLACE()
  • SQLite:REPLACE() function cascade
  • SQL Server:REPLACE() function cascade

Breaking Changes

None - this is a new optional feature that is disabled by default.

Fixes#3249

- 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.Fixesyajra#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 valuesThese 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 filesThese 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 guidelinesThis 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 stringsThese changes should resolve SonarQube security hotspots and reliability concerns.
@sonarqubecloud
Copy link

Quality Gate FailedQuality 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 extensionSonarQube for IDE

@Seb33300
Copy link
Contributor

Hi@slowestwind, which database are you using?
To support accent-insensitive search, the proper way is to configure your database with an appropriate collation.

With MySQL, this can be done using collations such asutf8mb4_unicode_ci.
With PostgreSQL, this is usually achieved by using a suitable collation together with theunaccent extension in your queries.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug when filtering words with accents

2 participants

@slowestwind@Seb33300

[8]ページ先頭

©2009-2025 Movatter.jp