clean search query
Posted: Tue Apr 25, 2006 2:57 am
This is the code snippets written while making the search scipt. Hope this might be useful :
Cheers,
Dibyendra
Code: Select all
$stop_words = array("/(\s)+AND(\s)+/i", "/(\s)+OR(\s)+/i", "/(\s)+NOT(\s)+/i");
$replace_words = array(" ", " ", " ");
$stop_chars = array("`" , "~", "!", "@", "#", "$", "%", "^", "&", "*", "-", "+", "|", "\\", "/", ":", ";", ".", ",");
//$replace_chars = array(" " , " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ");
$x_page_id = @$HTTP_POST_VARS["x_page_id"];
$search_string = $HTTP_POST_VARS["x_query"];
//$words = explode(" ", $search_string);
//for($counter = 0; $counter < count($words); $counter++ ) {
// if(empty($words[$counter]) || $words[$counter]==""){
// unset($words[$counter]);
// }
//}
$search_string = trim($search_string);
$search_string = strtolower($HTTP_POST_VARS["x_query"]);
//$search_string = preg_replace("/(\s)+/", " ", $search_string);
$search_string = preg_replace (
array (
'/\s+/', // Any space(s)
'/^\s+/', // Any space(s) at the beginning
'/\s+$/' // Any space(s) at the end
),
array (
' ', // ... one space
'', // ... nothing
'' // ... nothing
),
$search_string
);
//$search_string = str_replace(".", " ", $search_string);
//$search_string = processKeyword($search_string);
$search_string = preg_replace($stop_words, $replace_words, $search_string);
//$search_string = preg_replace($stop_chars, $replace_char, $search_string);
$search_string = str_replace($stop_chars, "", $search_string);Cheers,
Dibyendra