use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
+use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
];
}
+/**
+ * Implements hook_theme_suggestions_HOOK().
+ */
+function search_theme_suggestions_search_result(array $variables) {
+ return ['search_result__' . $variables['plugin_id']];
+}
+
/**
* Implements hook_preprocess_HOOK() for block templates.
*/
// search_total. We use a LEFT JOIN between the two tables and keep only the
// rows which fail to join.
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", [], ['target' => 'replica']);
- $or = db_or();
+ $or = new Condition('OR');
foreach ($result as $word) {
$or->condition('word', $word->realword);
}
$text = Html::decodeEntities($text);
// Lowercase
- $text = Unicode::strtolower($text);
+ $text = mb_strtolower($text);
// Remove diacritics.
$text = \Drupal::service('transliteration')->removeDiacritics($text);
function search_expand_cjk($matches) {
$min = \Drupal::config('search.settings')->get('index.minimum_word_size');
$str = $matches[0];
- $length = Unicode::strlen($str);
+ $length = mb_strlen($str);
// If the text is shorter than the minimum word size, don't tokenize it.
if ($length <= $min) {
return ' ' . $str . ' ';
$chars = [];
for ($i = 0; $i < $length; $i++) {
// Add the next character off the beginning of the string to the queue.
- $current = Unicode::substr($str, 0, 1);
+ $current = mb_substr($str, 0, 1);
$str = substr($str, strlen($current));
$chars[] = $current;
if ($i >= $min - 1) {
// Note: PHP ensures the array consists of alternating delimiters and literals
// and begins and ends with a literal (inserting $null as required).
- $tag = FALSE; // Odd/even counter. Tag or no tag.
- $score = 1; // Starting score per word
- $accum = ' '; // Accumulator for cleaned up data
- $tagstack = []; // Stack with open tags
- $tagwords = 0; // Counter for consecutive words
- $focus = 1; // Focus state
-
- $scored_words = []; // Accumulator for words for index
+ // Odd/even counter. Tag or no tag.
+ $tag = FALSE;
+ // Starting score per word.
+ $score = 1;
+ // Accumulator for cleaned up data.
+ $accum = ' ';
+ // Stack with open tags.
+ $tagstack = [];
+ // Counter for consecutive words.
+ $tagwords = 0;
+ // Focus state.
+ $focus = 1;
+
+ // Accumulator for words for index.
+ $scored_words = [];
foreach ($split as $value) {
if ($tag) {
// Increase or decrease score per word based on tag
list($tagname) = explode(' ', $value, 2);
- $tagname = Unicode::strtolower($tagname);
+ $tagname = mb_strtolower($tagname);
// Closing or opening tag?
if ($tagname[0] == '/') {
$tagname = substr($tagname, 1);
foreach ($words as $word) {
// Add word to accumulator
$accum .= $word . ' ';
- // Check wordlength
- if (is_numeric($word) || Unicode::strlen($word) >= $minimum_word_size) {
+ // Check word length.
+ if (is_numeric($word) || mb_strlen($word) >= $minimum_word_size) {
if (!isset($scored_words[$word])) {
$scored_words[$word] = 0;
}
$text = trim(preg_replace('/' . $preceded_by_boundary . '(?:' . implode('|', $keys) . ')' . $followed_by_boundary . '/iu', '<strong>\0</strong>', ' ' . $text . ' '));
return [
'#markup' => $text,
- '#allowed_tags' => ['strong']
+ '#allowed_tags' => ['strong'],
];
}
// See if there is a match after lower-casing and removing diacritics in
// both, which should preserve the string length.
- $new_text = Unicode::strtolower($text);
+ $new_text = mb_strtolower($text);
$new_text = \Drupal::service('transliteration')->removeDiacritics($new_text);
- $new_key = Unicode::strtolower($temp);
+ $new_key = mb_strtolower($temp);
$new_key = \Drupal::service('transliteration')->removeDiacritics($new_key);
if (preg_match('/' . $preceded_by_boundary . preg_quote($new_key, '/') . $followed_by_boundary . '/u', ' ' . $new_text . ' ')) {
- $position = Unicode::strpos($new_text, $new_key);
- return Unicode::substr($text, $position, Unicode::strlen($new_key));
+ $position = mb_strpos($new_text, $new_key);
+ return mb_substr($text, $position, mb_strlen($new_key));
}
// Run both text and key through search_simplify.
$proposed_end_index = floor(($max_end_index + $min_end_index) / 2);
$proposed_end_pos = $words[$proposed_end_index][1];
// Since the split was done with preg_split(), the positions are byte counts
- // not character counts, so use substr() not Unicode::substr() here.
+ // not character counts, so use substr() not mb_substr() here.
$trial_text = trim(search_simplify(substr($text, $start_pos, $proposed_end_pos - $start_pos), $langcode));
if (strpos($trial_text, $simplified_key) !== FALSE) {
// The proposed endpoint is fine, text still matches.
$proposed_start_index = ceil(($max_start_index + $min_start_index) / 2);
$proposed_start_pos = $words[$proposed_start_index][1];
// Since the split was done with preg_split(), the positions are byte counts
- // not character counts, so use substr() not Unicode::substr() here.
+ // not character counts, so use substr() not mb_substr() here.
$trial_text = trim(search_simplify(substr($text, $proposed_start_pos, $end_pos - $proposed_start_pos), $langcode));
if (strpos($trial_text, $simplified_key) !== FALSE) {
// The proposed start point is fine, text still matches.
$start_index = $max_start_index;
// Return the matching text. We need to use substr() here and not the
- // Unicode::substr() function, because the indices in $words came from
- // preg_split(), so they are Unicode-safe byte positions, not character
- // positions.
+ // mb_substr() function, because the indices in $words came from preg_split(),
+ // so they are Unicode-safe byte positions, not character positions.
return trim(substr($text, $words[$start_index][1], $words[$end_index][1] - $words[$start_index][1]));
}