Skip to content
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

Fix Synonyms case sensitive issue #3857

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update test
  • Loading branch information
burhandodhy committed Mar 8, 2024
commit 14401acb9fdad8f6f3cda2da81b215f4037e25cc
41 changes: 32 additions & 9 deletions includes/classes/Feature/Search/Synonyms.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,12 @@ public function add_search_synonyms( $mapping, $index ) {
$mapping['settings']['analysis']['filter'][ $filter_name ] = $this->get_synonym_filter();

// Tell the analyzer to use our newly created filter.
$mapping['settings']['analysis']['analyzer']['default_search']['filter'] = array_values(
array_merge(
$mapping['settings']['analysis']['analyzer']['default_search']['filter'],
[ $filter_name ]
$mapping['settings']['analysis']['analyzer']['default_search']['filter'] = $this->maybe_change_filter_position(
array_values(
array_merge(
[ $filter_name ],
$mapping['settings']['analysis']['analyzer']['default_search']['filter'],
)
)
);

Expand Down Expand Up @@ -483,11 +485,13 @@ function( $success, $index ) {
$setting['index']['analysis']['filter']['ep_synonyms_filter'] = $filter;

// Add the analyzer.
$setting['index']['analysis']['analyzer']['default_search']['filter'] = array_values(
array_unique(
array_merge(
$filters,
[ $this->get_synonym_filter_name() ]
$setting['index']['analysis']['analyzer']['default_search']['filter'] = $this->maybe_change_filter_position(
array_values(
array_unique(
array_merge(
[ $this->get_synonym_filter_name() ],
$filters
)
)
)
);
Expand Down Expand Up @@ -823,4 +827,23 @@ private function update_synonym_post( $content ) {
true
);
}

/**
* Change the position of the lowercase filter to the beginning of the array.
*
* @param array $filters Array of filters.
*
* @return array
*/
private function maybe_change_filter_position( $filters ) {
felipeelia marked this conversation as resolved.
Show resolved Hide resolved
$lowercase_index = array_search( 'lowercase', $filters, true );

if ( false !== $lowercase_index ) {
unset( $filters[ $lowercase_index ] );
array_unshift( $filters, 'lowercase' );
}

return $filters;
}

}
2 changes: 1 addition & 1 deletion tests/php/features/TestSynonyms.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function test_synonyms_with_spaces() {
* @since 5.1.0
* @group synonyms
*/
public function testSynonymsCaseInsensitive() {
public function test_synonyms_case_insensitive() {
$instance = $this->getFeature();

$this->ep_factory->post->create(
Expand Down
Loading