Подскажите пожалуйста.
Есть работающий скрипт поиска по сайту:
http://www.teploenergoplast.ru/search.phpЕсли ввести "РАДИАТОРЫ" найдется один документ, а именно
http://www.teploenergoplast.ru/rad/st_kermi.phpтак как в нем есть слово это слово именно с заглавных букв.
Вводим "Радиаторы" - находится 10 документов, это те в которых присутствует это слово, если оно начинается с заглавной,
а все остальные буквы прописные.
Вводим "радиаторы" и тут уже 34 документа, включающие в себя все предыдущие (и этот
http://www.teploenergoplast.ru/rad/st_kermi.php).
Как бы сделать так, чтобы скрипт не обращал внимание на регистр и выводил все?
Вариант, чтобы поисковый запрос преобразовывался в прописные не подойдет,
так как например по зпаросу "ппу" находится 9 документов, а "ППУ" - 10, тут все наоборот.
search.php
include "config.php";
$time1 = getmicrotime();
read_template("template.htm");
$stpos = 0;
$stype = "AND";
$query = "";
$abort = 0;
get_query();
if (count($query_arr) > 0) {
get_results();
$time3 = getmicrotime();
$time = $time3-$time1;
# print "
get_results() took $time sec.
";
boolean();
$time4 = getmicrotime();
$time = $time4-$time3;
$search_time = $time4-$time1;
$search_time = sprintf("%2.4f", $search_time);
# print "
boolean() took $time sec.
";
}
print print_template("header");
if (count($query_arr) > 0) {
if ($rescount>0) {
print print_template("results_header");
print_results();
print print_template("results_footer");
} else {
print print_template("no_results");
}
} else {
print print_template("empty_query");
}
print print_template("footer");
#=====================================================================
function get_query() {
global $HTTP_GET_VARS;
global $query, $stpos, $stype, $query_arr, $wholeword, $querymode, $stop_words_array;
global $min_length;
$query = $HTTP_GET_VARS["query"];
$stpos = $HTTP_GET_VARS["stpos"];
$stype = $HTTP_GET_VARS["stype"];
$query = strtolower($query);
$query = preg_replace("/[^a-zа-яA-ZА-Я +!]/"," ",$query);
$query_arr_dum = preg_split("/\\s+/",$query);
foreach($query_arr_dum as $word) {
if (strlen($word) < $min_length) { continue; }
if (array_key_exists($word,$stop_words_array)) { continue; }
$query_arr[] = $word;
}
for ($i=0; $i
if (preg_match("/\\!/", $query_arr[$i])) { $wholeword[$i] = 1;} # WholeWord
$query_arr[$i] = preg_replace("/[\\! ]/","",$query_arr[$i]);
if ($stype == "AND") { $querymode[$i] = 2;} # AND
if (preg_match ("/^\\-/", $query_arr[$i])) { $querymode[$i] = 1;} # NOT
if (preg_match ("/^\\+/", $query_arr[$i])) { $querymode[$i] = 2;} # AND
$query_arr[$i] = preg_replace("/^[\\+\\- ]/","",$query_arr[$i]);
}
if ($stpos <0) {$stpos = 0;};
}
#=====================================================================
function get_results() {
global $HASHSIZE, $INDEXING_SCHEME, $HASH, $HASHWORDS, $FINFO, $SITEWORDS, $WORD_IND;
global $query_arr, $wholeword, $querymode;
global $res, $allres, $rescount, $query_statistics;
$fp_HASH = fopen ("$HASH", "rb");
$fp_HASHWORDS = fopen ("$HASHWORDS", "rb");
$fp_SITEWORDS = fopen ("$SITEWORDS", "rb");
$fp_WORD_IND = fopen ("$WORD_IND", "rb");
for ($j=0; $j
$query = $query_arr[$j];
$allres[$j] = array();
if ($INDEXING_SCHEME == 1) {
$substring_length = strlen($query);
} else {
$substring_length = 4;
}
$hash_value = abs(hash(substr($query,0,$substring_length)) % $HASHSIZE);
fseek($fp_HASH,$hash_value*4,0);
$dum = fread($fp_HASH,4);
$dum = unpack("Ndum", $dum);
fseek($fp_HASHWORDS,$dum[dum],0);
$dum = fread($fp_HASHWORDS,4);
$dum1 = unpack("Ndum", $dum);
for ($i=0; $i<$dum1[dum]; $i++) {
$dum = fread($fp_HASHWORDS,8);
$arr_dum = unpack("Nwordpos/Nfilepos",$dum);
fseek($fp_SITEWORDS,$arr_dum[wordpos],0);
$word = fgets($fp_SITEWORDS,1024);
$word = preg_replace("/\\x0A/","",$word);
$word = preg_replace("/\\x0D/","",$word);
if ( ($wholeword[$j]==1) && ($word != $query) ) {$word = "";};
$pos = strpos($word, $query);
if ($pos !== false) {
fseek($fp_WORD_IND,$arr_dum[filepos],0);
$dum = fread($fp_WORD_IND,4);
$dum2 = unpack("Ndum",$dum);
$dum = fread($fp_WORD_IND,$dum2[dum]*4);
for($k=0; $k<$dum2[dum]; $k++){
$zzz = unpack("Ndum",substr($dum,$k*4,4));
$allres[$j][$zzz[dum]] = 1;
}
}
};
}
for ($j=0; $j
$found_number = count($allres[$j]);
$query_statistics .= " $query_arr[$j]-$found_number\\n";
}
}
#=====================================================================
function boolean() {
global $query_arr, $querymode, $stype;
global $res, $allres, $rescount;
if (count($query_arr) == 1) {
foreach ($allres[0] as $k => $v) {
if ($k) {
$res .= pack("N",$k);
}
}
$rescount = intval(strlen($res)/4);
unset($allres);
return;
} else {
if ($stype == "AND") {
for ($i=0; $i
if ($querymode[$i] == 2) {
$min = $i;
break;
}
}
for ($i=$min+1; $i
if (count($allres[$i]) < count($allres[$min]) && $querymode[$i] == 2) {
$min = $i;
}
}
for ($i=0; $i
if ($i == $min) {
continue;
}
if ($querymode[$i] == 2) {
foreach ($allres[$min] as $k => $v) {
if (array_key_exists($k,$allres[$i])) {
} else {
unset($allres[$min][$k]);
}
}
} else {
foreach ($allres[$min] as $k => $v) {
if (array_key_exists($k,$allres[$i])) {
unset($allres[$min][$k]);
}
}
}
}
foreach ($allres[$min] as $k => $v) {
if ($k) {
$res .= pack("N",$k);
}
}
$rescount = intval(strlen($res)/4);
return;
}
if ($stype == "OR") {
for ($i=0; $i
if ($querymode[$i] != 1) {
$max = $i;
break;
}
}
for ($i=$max+1; $i
if (count($allres[$i]) > count($allres[$min]) && $querymode[$i] != 1) {
$max = $i;
}
}
for ($i=0; $i
if ($i == $max) {
continue;
}
if ($querymode[$i] != 1) {
foreach ($allres[$i] as $k => $v) {
$allres[$max][$k] = 1;
}
} else {
foreach ($allres[$i] as $k => $v) {
if (array_key_exists($k,$allres[$max])) {
unset($allres[$max][$k]);
}
}
}
}
foreach ($allres[$max] as $k => $v) {
if ($k) {
$res .= pack("N",$k);
}
}
$rescount = intval(strlen($res)/4);
return;
}
}
}
#=====================================================================
function print_results() {
global $FINFO, $FINFO_IND, $query, $stpos, $stype, $res_num, $res;
global $url, $title, $size, $description, $rescount, $next_results;
$time1 = getmicrotime();
$fp_FINFO = fopen ("$FINFO", "rb");
for ($i=$stpos; $i<$stpos+$res_num; $i++) {
if ($i >= strlen($res)/4) {break;};
$strpos = unpack("Npos",substr($res,$i*4,4));
fseek($fp_FINFO,$strpos[pos],0);
$dum = fgets($fp_FINFO,4024);
list($url, $size, $title, $description) = explode("::",$dum);
print print_template("results");
}; # for
if ($rescount <= $res_num) {$next_results = ""; return 1;}
$mhits = 20 * $res_num;
$pos2 = $stpos - $stpos % $mhits;
$pos1 = $pos2 - $mhits;
$pos3 = $pos2 + $mhits;
if ($pos1 < 0) { $prev = ""; }
else {
$prev = "
$prev .= ">PREV \\n";
}
if ($pos3 > $rescount) { $next = ""; }
else {
$next = "
$next .= ">NEXT \\n";
}
$next_results .= $prev;
$next_results .= " |\\n";
for ($i=$pos2; $i<$pos3; $i += $res_num) {
if ($i >= $rescount) {break;}
$page_number = $i/$res_num+1;
if ( $i != $stpos ) {
$next_results .= "
$next_results .= ">".$page_number." |\\n";
} else {
$next_results .= $page_number." |\\n";
}
}
$next_results .= $next;
}
#=====================================================================
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
#=====================================================================
function hash($key) {
$chars = preg_split("//",$key);
for($i=1;$i
$chars2[$i] = ord($chars[$i]);
}
$h = hexdec("00000000");
$f = hexdec("F0000000");
for($i=1;$i
$h = ($h << 4) + $chars2[$i];
if ($g = $h & $f) { $h ^= $g >> 24; };
$h &= ~$g;
}
return $h;
}
#===================================================================
function read_template($filename) {
$size = filesize($filename);
$fd = fopen ($filename, "rb");
$template = fread ($fd, $size);
fclose ($fd);
global $templates;
$count = preg_match_all("/(.*?)/s", $template, $matches, PREG_SET_ORDER);
for($i=0; $i < count($matches); $i++) {
$templates[$matches[$i][1]] = $matches[$i][2];
}
}
#===================================================================
function print_template($part) {
global $templates;
global $query, $search_time, $query_statistics, $stpos, $url, $title, $size, $description, $rescount, $next_results;
$template = $templates[$part];
$template = preg_replace("/%query%/s","$query",$template);
$template = preg_replace("/%search_time%/s","$search_time",$template);
$template = preg_replace("/%query_statistics%/s","$query_statistics",$template);
$template = preg_replace("/%stpos%/s",$stpos+1,$template);
$template = preg_replace("/%url%/s","$url",$template);
$template = preg_replace("/%title%/s","$title",$template);
$template = preg_replace("/%size%/s","$size",$template);
$template = preg_replace("/%description%/s","$description",$template);
$template = preg_replace("/%rescount%/s","$rescount",$template);
$template = preg_replace("/%next_results%/s","$next_results",$template);
return $template;
}
#===================================================================
?>