function indexText($text, $type, $id, &$trigramValues, &$suggestionValues) { if (!trim($text)) { return; } static $stopWords, $db; if (!$stopWords) { $stopWords = Lms_Application::getConfig('indexing', 'stop_words'); } if (!$db) { $db = Lms_Db::get('main'); } $trigrams = array(); $textLength = Lms_Text::length($text); if ($textLength >= 3) { for ($i = 0; $i <= $textLength - 3; $i++) { $trigram = substr($text, $i, 3); $trigramValues[] = sprintf("('%s','%s',%d)", mysql_real_escape_string(strtolower($trigram)), $type, $id); } } preg_match_all('{\\w{2,}}', strtolower($text), $words, PREG_PATTERN_ORDER); $wordsFiltered = array(); foreach (array_diff($words[0], $stopWords) as $word) { if (!preg_match('{^\\d+$}', $word)) { $wordsFiltered[] = $word; } } array_unshift($wordsFiltered, strtolower($text)); //print_r($wordsFiltered); foreach ($wordsFiltered as $word) { $suggestionValues[] = sprintf("('%s','%s',%d)", mysql_real_escape_string(trim($word, ' .\'"')), $type, $id); } }
public function urlToPath($fileUrl) { if (Lms_Text::pos($fileUrl, 'file:///localhost/') === 0) { $filePath = Lms_Text::replace("\\", '/', Lms_Text::replace('file:///localhost/', '', $fileUrl)); } elseif (Lms_Text::pos($fileUrl, 'file://localhost/') === 0) { $filePath = Lms_Text::replace("\\", '/', Lms_Text::replace('file://localhost/', '', $fileUrl)); } elseif (Lms_Text::pos($fileUrl, 'file:///') === 0) { $filePath = Lms_Text::replace("\\", '/', Lms_Text::replace('file:///', '', $fileUrl)); } elseif (Lms_Text::pos($fileUrl, 'file://') === 0) { $filePath = Lms_Text::replace("\\", '/', Lms_Text::replace('file://', '', $fileUrl)); } else { $filePath = $fileUrl; } if ($filePath[Lms_Text::length($filePath) - 1] == '/') { $filePath = Lms_Text::substring($filePath, 0, strlen($filePath) - 1); } return $filePath; }
private static function matchStrings($str1, $str2) { return self::compareStrings($str1, $str2) <= self::maxLevensteinDistance(Lms_Text::length($str1)); }