{{toc numerate=1}}
===Search Highlighter===
====Full words====
Search action: Highlight only full words. (default)
%%(php)
<?php
$highlight_this = function ($text, $words)
{
$text = Ut::html($text);
$words = trim($words);
$words_array = explode(' ', $words);
$boundaries = '[\\p{Z}\\p{P}\\p{C}]';
if ($words_array)
{
$pat_pre = "(^|{$boundaries})";
$pat_post = "({$boundaries}|$)";
foreach ($words_array as $word)
{
// escape bad regex characters
$word = preg_quote($word, '/');
$pattern = "/$pat_pre(" . $word . ")$pat_post/ui";
$text = preg_replace($pattern, "\\1<mark class='highlight'>\\2</mark>\\3", $text);
}
}
return $text;
};
%%
====Strings====
Search action: Highlight strings. (##hl_simple=1##)
Ideographic languages such as Chinese and Japanese do not have word delimiters.
%%(php)
<?php
$highlight_simple = function ($text, $words)
{
$hl_words = [];
$text = Ut::html($text);
$words = trim($words);
$words_array = explode(' ', $words);
if ($words_array)
{
foreach ($words_array as $word)
{
// escape bad regex characters
$hl_words[] = preg_quote($word, '/');
}
$pattern = implode('|', $hl_words);
$text = preg_replace('/(' . $pattern . ')/ui', '<mark class="highlight">$1</mark>', $text);
}
return $text;
};
%%
===ngram Full-Text Parser===
((/Dev/Release/R6.0/UnicodeIssues/ngramFull-TextParser InnoDB full-text index for Chinese search)), not supported by MariaDB.
Add add ##WITH PARSER ngram## by alter the page table
%%(hl sql)
ALTER TABLE page ADD FULLTEXT INDEX ft_index (title, body) WITH PARSER ngram;
%%