использую код с версии 1.2
function split_words($text)
{
global $pun_user;
static $noise_match, $noise_replace, $stopwords;
if (empty($noise_match))
{
$noise_match = array('[quote', '[code', '[url', '[img', '[email', '[color', '[colour', 'quote]', 'code]', 'url]', 'img]', 'email]', 'color]', 'colour]', '^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '+', '[', ']', '{', '}', ':', '\\', '/', '=', '#', ';', '!', '*');
$noise_replace = array('', '', '', '', '', '', '', '', '', '', '', '', '', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ', ' ');
$stopwords = (array)@file(PUN_ROOT.'lang/'.$pun_user['language'].'/stopwords.txt');
$stopwords = array_map('trim', $stopwords);
}
// Clean up
$patterns[] = '#&[\#a-z0-9]+?;#i';
$patterns[] = '#\b[\w]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/~]+)?#';
$patterns[] = '#\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]#';
$text = preg_replace($patterns, ' ', ' '.strtolower($text).' ');
// Filter out junk
$text = str_replace($noise_match, $noise_replace, $text);
// Strip out extra whitespace between words
$text = trim(preg_replace('#\s+#', ' ', $text));
// Fill an array with all the words
$words = explode(' ', $text);
if (!empty($words))
{
while (list($i, $word) = @each($words))
{
$words[$i] = trim($word, '.');
$num_chars = pun_strlen($word);
if ($num_chars < 3 || $num_chars > 20 || in_array($word, $stopwords))
unset($words[$i]);
}
}
return array_unique($words);
}
так вот - переодически выскакиет ошибка при добалении сообщения (или при переиндексации форума) типа "Duplicate entry 'смс' for key 1", т.е. говорит, что такое слово уже есть в таблице и ругается на слово допустим "смс", т.е. если в таблице есть слово "смс", то слово "СмС" или "Смс" или "сМС" при добавлении сообщения вызовит ошибку "дубликат".
пытался использовать код с версии 1.3
function split_words($text)
{
// Remove BBCode
$text = preg_replace('/\[\/?(b|u|i|h|colou?r|quote|code|img|url|email|list)(?:\=[^\]]*)?\]/', ' ', $text);
// Remove any apostrophes which aren't part of words
$text = substr(preg_replace('((?<=\W)\'|\'(?=\W))', '', ' '.$text.' '), 1, -1);
// Remove symbols and multiple whitespace
$text = preg_replace('/[\^\$&\(\)<>`"\|,@_\?%~\+\[\]{}:=\/#\\\\;!\*\.\s]+/', ' ', $text);
// Fill an array with all the words
$words = array_unique(explode(' ', $text));
// Remove any words that should not be indexed
$words = array_filter($words, 'validate_search_word');
if ($return != null)
return $return;
return $words;
}
но такой код записывает в базу только цифры, (использую кодировку windows-1251)
ставил поле search_words.word вида word VARBINARY(60)
но при моей кодировке в одну базу записывается или квадратики либо числа и иероглифы
if ($num_chars < 3 || $num_chars > 20 || in_array($word, $stopwords))
менял на 60
на локальном компе все нормально работает, какие будут варианты решения, помогите пожалуйста