summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Seidl2018-01-27 15:41:03 (GMT)
committerThomas Seidl2018-01-27 15:41:03 (GMT)
commit848bff3a49f2fa1a4b3626a542fbe09f171d3702 (patch)
tree862b4ef37e12f3d928e0d2475a4acb4c202f8b13
parentc2a1bf24883c406707c6806339ad6c06583454ad (diff)
Issue #2932347 by drunken monkey, ghaya: Fixed case insensitive matching for highlighting non-ASCII text.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--src/Plugin/search_api/processor/Highlight.php8
-rw-r--r--tests/src/Unit/Processor/HighlightTest.php16
3 files changed, 19 insertions, 7 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 8b1c178..53040d9 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 9e23eb7..195b7d5 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 b62be7a..02d31b1 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 longwordtoshow<strong>partial</strong>matching 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<strong>ähr</strong>.',
- ],
- ];
+ ];
+ }
+
+ return $data_sets;
}
/**