diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8b1c1787dc7c74fdb66780f59e4bc70d903ffd00..53040d9a9c531ddc7f570b0578cffd5508fa9224 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,7 @@ Search API 1.x, dev (xxxx-xx-xx): --------------------------------- +- #2932347 by drunken monkey, ghaya: Fixed case insensitive matching for + highlighting non-ASCII text. - #2938288 by drunken monkey: Fixed problems with PHP 7.2. - #2934321 by Graber, drunken monkey: Fixed Views total for views with pager offset. diff --git a/src/Plugin/search_api/processor/Highlight.php b/src/Plugin/search_api/processor/Highlight.php index 9e23eb7f048702149be9d9afdb96e7985defc424..195b7d5746194fd1cd4abda75773f0dcafbcd895 100644 --- a/src/Plugin/search_api/processor/Highlight.php +++ b/src/Plugin/search_api/processor/Highlight.php @@ -472,16 +472,18 @@ class Highlight extends ProcessorPluginBase implements PluginFormInterface { // and ends with a space. $matches = []; - $found_position = FALSE; if (!$this->configuration['highlight_partial']) { + $found_position = FALSE; $regex = '/' . self::$boundary . preg_quote($key, '/') . self::$boundary . '/iu'; if (preg_match($regex, ' ' . $text . ' ', $matches, PREG_OFFSET_CAPTURE, $look_start[$key])) { $found_position = $matches[0][1]; } } + elseif (function_exists('mb_stripos')) { + $found_position = mb_stripos($text, $key, $look_start[$key], 'UTF-8'); + } else { - $function = function_exists('mb_stripos') ? 'mb_stripos' : 'stripos'; - $found_position = $function($text, $key, $look_start[$key]); + $found_position = stripos($text, $key, $look_start[$key]); } if ($found_position !== FALSE) { $look_start[$key] = $found_position + 1; diff --git a/tests/src/Unit/Processor/HighlightTest.php b/tests/src/Unit/Processor/HighlightTest.php index b62be7aec9f6d86a47c08c3bf52e7c24f2312e75..02d31b1588b9f84e6dd0a1c60a85e75351b0303d 100644 --- a/tests/src/Unit/Processor/HighlightTest.php +++ b/tests/src/Unit/Processor/HighlightTest.php @@ -356,18 +356,26 @@ class HighlightTest extends UnitTestCase { * @see \Drupal\Tests\search_api\Unit\Processor\HighlightTest::testPostprocessSearchResultsHighlightPartial() */ public function postprocessSearchResultsHighlightPartialDataProvider() { - return [ + $data_sets = [ 'normal' => [ 'Some longwordtoshowpartialmatching value', 'partial', 'Some longwordtoshowpartialmatching value', ], - 'multi-byte' => [ + ]; + + // Test multi-byte support only if this PHP installation actually contains + // the necessary function. Otherwise, we can't really be blamed for not + // supporting them. + if (function_exists('mb_stripos')) { + $data_sets['multi-byte'] = [ 'Alle Angaben ohne Gewähr.', 'Ähr', 'Alle Angaben ohne Gewähr.', - ], - ]; + ]; + } + + return $data_sets; } /**