Provide ability to offer search suggestions in other (not 'en') languages.

This commit is contained in:
Retro_Guy 2024-12-14 06:27:36 -07:00
parent 933fe81371
commit 60b43050c2
4 changed files with 45 additions and 23 deletions

View File

@ -155,6 +155,12 @@ if (!isset($OVERRIDES['disable_msgid_search']) || $OVERRIDES['disable_msgid_sear
}
}
// For debugging purposes
if (isset($OVERRIDES['log_lang']) && $OVERRIDES['log_lang'] == true) {
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
file_put_contents($debug_log, "\n" . logging_prefix() . " Browser Lang: " . $lang, FILE_APPEND);
}
// Soup...Uh, Message of the Day
if ($unread) {
$motd = '*** You have unread mail. <a href="../spoolnews/mail.php">Click Here</a> ***';

View File

@ -2443,6 +2443,7 @@ function throttle_hits($client_device = null)
function get_client_user_agent_info()
{
global $config_dir, $logdir;
// Try to get browser info to use for extra formatting of page
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
$devices = array(

View File

@ -8,7 +8,7 @@ header("Pragma: cache");
include "config.inc.php";
include "newsportal.php";
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$logfile = $logdir . '/search.log';
$snippet_size = 100;
@ -142,9 +142,10 @@ if (isset($_POST['block_poster'])) {
}
display_search_tools();
if ($lang == 'en') { // Display suggestions
// Display search suggestions
if (isset($_REQUEST['searchpoint']) && $_REQUEST['searchpoint'] == 'body' && isset($_REQUEST['terms']) && trim($_REQUEST['terms']) != '') {
$suggestion = get_suggestion($_REQUEST['terms'], $lang);
$suggestion = get_suggestion($_REQUEST['terms']);
if ($suggestion != false) {
echo '<form method="post" action="search.php" class="search_suggestion_inline">';
@ -158,9 +159,10 @@ if ($lang == 'en') { // Display suggestions
echo 'Did you mean: <b><i>' . htmlentities($suggestion) . '</i></b>';
echo '</button>';
echo '</form>';
file_put_contents($logfile, "\n" . logging_prefix() . " SEARCH: " . $_REQUEST['terms'] . " SUGGESTING: " . $suggestion, FILE_APPEND);
}
}
}
echo "<hr>";
ob_start();
@ -546,14 +548,19 @@ function display_search_tools($home = true)
echo '</tr></table></form>';
}
function get_suggestion($word, $lang)
function get_suggestion($word)
{
if ($lang != 'en') {
return false;
}
$pspell = pspell_new("en");
global $OVERRIDES;
// Remove non alpha characters here
if (isset($OVERRIDES['lang_default'])) {
$lang = $OVERRIDES['lang_default'];
} else {
$lang = 'en';
}
$pspell = pspell_new($lang);
// Remove specific characters here
$word = preg_replace("/(\"\'\+\-\_)/", '', $word);
if (!preg_match("/ /", trim($word))) { // Just one word in search

View File

@ -143,6 +143,14 @@ return [
// Rate per second that a 'bot' may load pages
'throttle_hits_bot_loadrate' => '.1',
// Set 'log_lang' to true to log client browser language to debug.log
//'log_lang' => true,
// Set default language for search suggestions
// YOU MUST INSTALL aspell-xx for the language you wish to use
// Default is 'en' (english)
'lang_default' => 'en',
// Use this to create notices for things identified in msg body
// 'regex' must be a full regex, including delimiters
'display_notice_for_body_checks' => array(