быстрый поиск работает , заценил.
вот только не все посты индексированны на поиск руского текста.
пример:
пост
https://airgun.org.ru/forum/viewtopic.php?t=261 (древний)
ищем слово "Скороспороновоговорилки" - не находим.
проблемма в том что когда начинался форум движок не создавал списки индексных слов для русского языка.
лечится это однократным реиндексированием
вот код таблетки :
открываем файл include/functions_search.php
в нём ищим (в функции clean_words)
Код:
static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
$entry = ' ' . strip_tags(strtolower($entry)) . ' ';
непосредственно за этим добавляем фикс русскоязычный:
Код:
# --- Setar mod ---
# конвертируем русские буквы в нижний регистр
$entry = strtr ($entry,"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ","абвгдеёжзийклмнопрстуфхцчшщъыьэюя");
# --- end Setar mod ---
далее добавляем новую функцию - реиндексирования постов
Код:
# --- Setar mod ---
#############################################
function rescan_search_words ()
#############################################
{
global $db, $phpbb_root_path, $board_config, $lang;
$query = "DELETE FROM phpbb_search_wordlist";
$result = mysql_query($query);
$query = "DELETE FROM phpbb_search_wordmatch";
$result = mysql_query($query);
$query = "SELECT * from phpbb_posts_text";
$result = mysql_query($query);
while ( $scan = $db->sql_fetchrow($result) )
{
$post_id=$scan['post_id'];
$post_text=$scan['post_text'];
$post_title =$scan['post_subject'];
//print "Debug: $post_id<br>";
###########################################################################################
$stopwords_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_stopwords.txt");
$synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_synonyms.txt");
/*
$a = $synonym_array;
$i=0;
while ($i<10){
echo "debug: a[$i]=$a[$i]<br>";
$i++;
};
*/
$search_raw_words = array();
$search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array));
$search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array));
$word = array();
$word_insert_sql = array();
while ( list($word_in, $search_matches) = @each($search_raw_words) )
{
$word_insert_sql[$word_in] = '';
if ( !empty($search_matches) )
{
for ($i = 0; $i < count($search_matches); $i++)
{
$search_matches[$i] = trim($search_matches[$i]);
if( $search_matches[$i] != '' )
{
$word[] = $search_matches[$i];
if ( !strstr($word_insert_sql[$word_in], "'" . $search_matches[$i] . "'") )
{
$word_insert_sql[$word_in] .= ( $word_insert_sql[$word_in] != "" ) ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'";
}
}
}
}
}
if ( count($word) )
{
sort($word);
$prev_word = '';
$word_text_sql = '';
$temp_word = array();
for($i = 0; $i < count($word); $i++)
{
if ( $word[$i] != $prev_word )
{
$temp_word[] = $word[$i];
$word_text_sql .= ( ( $word_text_sql != '' ) ? ', ' : '' ) . "'" . $word[$i] . "'";
}
$prev_word = $word[$i];
}
$word = $temp_word;
$check_words = array();
switch( SQL_LAYER )
{
case 'postgresql':
case 'msaccess':
case 'mssql-odbc':
case 'oracle':
case 'db2':
$sql = "SELECT word_id, word_text
FROM " . SEARCH_WORD_TABLE . "
WHERE word_text IN ($word_text_sql)";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not select words', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$check_words[$row['word_text']] = $row['word_id'];
}
break;
}
$value_sql = '';
$match_word = array();
for ($i = 0; $i < count($word); $i++)
{
$new_match = true;
if ( isset($check_words[$word[$i]]) )
{
$new_match = false;
}
if ( $new_match )
{
switch( SQL_LAYER )
{
case 'mysql':
case 'mysql4':
$value_sql .= ( ( $value_sql != '' ) ? ', ' : '' ) . '(\'' . $word[$i] . '\', 0)';
break;
case 'mssql':
$value_sql .= ( ( $value_sql != '' ) ? ' UNION ALL ' : '' ) . "SELECT '" . $word[$i] . "', 0";
break;
default:
$sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
VALUES ('" . $word[$i] . "', 0)";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
}
break;
}
}
}
if ( $value_sql != '' )
{
switch ( SQL_LAYER )
{
case 'mysql':
case 'mysql4':
$sql = "INSERT IGNORE INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
VALUES $value_sql";
break;
case 'mssql':
$sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
$value_sql";
break;
}
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
}
}
}
while( list($word_in, $match_sql) = @each($word_insert_sql) )
{
print "Debug: $word_in, $match_sql<br>";
$title_match = ( $word_in == 'title' ) ? 1 : 0;
if ( $match_sql != '' )
{
$sql = "INSERT INTO " . SEARCH_MATCH_TABLE . " (post_id, word_id, title_match)
SELECT $post_id, word_id, $title_match
FROM " . SEARCH_WORD_TABLE . "
WHERE word_text IN ($match_sql)";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not insert new word matches', '', __LINE__, __FILE__, $sql);
}
}
}
###########################################################################################
};
};
# --- end Setar mod ---
Эта функчия добавляется в любом месте , только не внутри другой функции.
у меня она идёт после функции clean_words, вот код её конца
Код:
return $entry;
}
на этом изменения в библиотеке поиска закончены.
функция рескана запускается таким файлом, выложеным в корне, например rescan_search.php затем файл можно удалить или периименовать. выполняется долго, может мин 30.
Код:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
rescan_search_words ();
exit(0);
?>