Add AND/OR/NOT to Search.

This commit is contained in:
Retro_Guy 2024-12-15 02:47:16 -07:00
parent 60b43050c2
commit a77ffab3b1

View File

@ -160,6 +160,8 @@ if (isset($_REQUEST['searchpoint']) && $_REQUEST['searchpoint'] == 'body' && iss
echo '</button>'; echo '</button>';
echo '</form>'; echo '</form>';
file_put_contents($logfile, "\n" . logging_prefix() . " SEARCH: " . $_REQUEST['terms'] . " SUGGESTING: " . $suggestion, FILE_APPEND); file_put_contents($logfile, "\n" . logging_prefix() . " SEARCH: " . $_REQUEST['terms'] . " SUGGESTING: " . $suggestion, FILE_APPEND);
} else {
file_put_contents($logfile, "\n" . logging_prefix() . " SEARCH: " . $_REQUEST['terms'], FILE_APPEND);
} }
} }
@ -550,7 +552,7 @@ function display_search_tools($home = true)
function get_suggestion($word) function get_suggestion($word)
{ {
global $OVERRIDES; global $OVERRIDES, $logfile;
if (isset($OVERRIDES['lang_default'])) { if (isset($OVERRIDES['lang_default'])) {
$lang = $OVERRIDES['lang_default']; $lang = $OVERRIDES['lang_default'];
@ -558,10 +560,13 @@ function get_suggestion($word)
$lang = 'en'; $lang = 'en';
} }
$pspell = pspell_new($lang); if(($pspell = pspell_new($lang)) == false) {
file_put_contents($logfile, "\n" . logging_prefix() . " SEARCH: " . $lang . " dictionary not found", FILE_APPEND);
return false;
}
// Remove specific characters here // Remove specific characters here
$word = preg_replace("/(\"\'\+\-\_)/", '', $word); $word = preg_replace("/(\"|\'|\(|\)|\-|\+|\_)/", '', $word);
if (!preg_match("/ /", trim($word))) { // Just one word in search if (!preg_match("/ /", trim($word))) { // Just one word in search
if (!pspell_check($pspell, $word)) { if (!pspell_check($pspell, $word)) {
@ -580,6 +585,10 @@ function get_suggestion($word)
$return_string = ''; $return_string = '';
$words = explode(" ", $word); $words = explode(" ", $word);
foreach ($words as $one_word) { foreach ($words as $one_word) {
if(preg_match("/^(AND|OR|NOT|\+)$/i", $one_word)) {
$return_string .= $one_word . " ";
continue;
}
if (!pspell_check($pspell, $one_word)) { if (!pspell_check($pspell, $one_word)) {
$suggestions = pspell_suggest($pspell, $one_word); $suggestions = pspell_suggest($pspell, $one_word);
if (isset($suggestions[0])) { if (isset($suggestions[0])) {
@ -592,7 +601,7 @@ function get_suggestion($word)
} }
} }
if (trim(strtolower($return_string)) != trim(strtolower($word))) { if (trim(strtolower($return_string)) != trim(strtolower($word))) {
return trim(strtolower($return_string)); return trim($return_string);
} else { } else {
return false; return false;
} }