0) { /* opredelyaem peremennie */ $epq_mode = $epq_i = $oq_mode = 0; /* reset array */ reset($query); /* while array */ while (list($i,$word) = each($query)) { /* epq */ if ($epq_mode != 1 && strlen($word) <= $config['search_min']) continue; if ($epq_mode == 0) { /* esli est " v nachale stoki */ if (preg_match("/^\"/",$word)) { /* esli net " v konce stroki */ if (!preg_match("/\"$/",$word)) { $epq[$epq_i] = substr($word,1); $epq_mode = 1; continue; } else { $epq[$epq_i] = substr($word,1,(strlen($word)-2)); $epq_i ++; continue; } } } else { /* esli est v konce " */ if (preg_match("/\"$/",$word)) { $epq[$epq_i] = $epq[$epq_i]." ".substr($word,0,(strlen($word)-1)); $epq_i ++; $epq_mode = 0; continue; } else { $epq[$epq_i] = $epq[$epq_i]." ".$word; continue; } } /* oq */ if ($oq_mode == 0) { /* esli sled OR */ if (isset($query[($i + 1)]) && $query[($i + 1)] == "OR") { $oq_mode = 1; $oq[] = $word; continue; } } else { if ($word == "OR") continue; else { if (isset($query[($i + 1)]) && $query[($i + 1)] == "OR") { $oq[] = $word; continue; } else { $oq[] = $word; $oq_mode = 0; continue; } } } /* eq */ if (preg_match("/^(\-)/",$word)) { $eq[] = substr($word,1); continue; } /* q */ $q[] = $word; } } if (isset($_GET['q']) && strlen($form_query) < 3) { $print_min = true; } /* delaem zapros k db esli suschestvuet zapros na poisk */ if ($form_query && !$print_min) { $r_q = $r_epq = $r_oq = $r_eq = array(); $count_q = count($q); $count_epq = count($epq); $count_oq = count($oq); $count_eq = count($eq); /* boolean query (so vsemi slovami) */ if ($count_q > 0) { /* ignore stop words && min symbols */ foreach ($q as $q_word) { if (strlen($q_word) >= $config['search_min']) $q_clean[] = addslashes($q_word); } /* check mysql version > 4.0.1 && on/off BOOLEAN MODE */ $boolean_mode = 0; $boolean_str = ""; $mysql_version = split("\.", mysql_get_server_info()); if ($mysql_version[0] == "4") { if ($mysql_version[1] == 0 && $mysql_version[2]{1} > 0) $boolean_mode = 1; if ($mysql_version[1] > 0) $boolean_mode = 1; } if ($mysql_version[0] > "4") $boolean_mode = 1; if ($boolean_mode == 1) $boolean_str = " IN BOOLEAN MODE"; $where_q = join(" ",$q_clean); $res_q = mysql_query("SELECT * FROM `{$tbl_name}` WHERE MATCH (`text`) AGAINST ('{$where_q}'{$boolean_str})"); if (mysql_num_rows($res_q) == 0) { $where_q = join("%",$q_clean); $res_q = mysql_query("SELECT * FROM `{$tbl_name}` WHERE `text`LIKE '%{$where_q}%'"); } while ($row_q = mysql_fetch_array($res_q)) { $r_q[$row_q['id']] = $row_q; } } /* tochnoe sovpadenie (s tochnoy frazoy) */ if ($count_epq > 0) { if ($count_epq > 1) $where_epq = "(".join("|",$epq).")"; else $where_epq = join("",$epq); $res_epq = mysql_query("SELECT * FROM `{$tbl_name}` WHERE `text` LIKE '%{$where_epq}%'"); while ($row_epq = mysql_fetch_array($res_epq)) { $r_epq[$row_epq['id']] = $row_epq; } } /* zapros na OR (so lubim iz slov) */ if ($count_oq > 0) { /* ignore stop words && min symbols */ foreach ($oq as $oq_word) { if (strlen($oq_word) <= $config['search_min']) $oq_clean[] = addslashes($oq_word); } $where_oq = join("|",$oq_clean); $res_oq = mysql_query("SELECT * FROM `{$tbl_name}` WHERE `text` REGEXP '{$where_oq}'"); while ($row_oq = mysql_fetch_array($res_oq)) { $r_oq[$row_oq['id']] = $row_oq; } } /* zapros (bez slov) */ if ($count_eq > 0) { foreach ($eq as $eq_word) { /* ignore stop words && min symbols */ if (strlen($eq_word) >= $config['search_min']) $eq_clean[] = addslashes($eq_word); } $where_eq = join("|",$eq_clean); $res_eq = mysql_query("SELECT * FROM `{$tbl_name}` WHERE `text` REGEXP '{$where_eq}'"); while ($row_eq = mysql_fetch_array($res_eq)) { $r_eq[$row_eq['id']] = $row_eq; } } /* opredelyaem result array */ $result = $search_res = array(); /* all result array */ $all = $r_q + $r_epq + $r_oq + $r_eq; if (count($all) > 0) { reset ($all); /* validate result */ while (list($i,$row) = each($all)) { $x = $y = 0; if ($count_q > 0) { $x ++; if (isset($r_q[$i])) $y ++; } if ($count_epq > 0) { $x ++; if (isset($r_epq[$i])) $y ++; } if ($count_oq > 0) { $x ++; if (isset($r_oq[$i])) $y ++; } if ($count_eq > 0) { $x ++; if (!isset($r_eq[$i])) $y ++; } if ($x == $y) $result[$i] = $row; } /* create pattern for preg */ if (count($epq) > 0) $q[] = join(" ",$epq); $pattern = join("|",$q); if (count($q) > 0 && count($oq) > 0) $pattern .= "|"; if (count($oq)) $pattern = join("|",$oq); $pattern_match = "/({$pattern})/siU"; $pattern_replace = "/({$pattern})/siU"; reset($result); $i = 0; while (list(,$row) = each($result)) { preg_match_all($pattern_match, $row['text'],$match); $search_res[$i]['rel'] = count($match[0]); $search_res[$i][1] = $row['title']; $search_res[$i][2] = ""; $search_res[$i][3] = $row['url']; $search_res[$i][4] = preg_replace("/^(http\:\/\/)(.*)/siU","\\2",$config['site_addr'].$row['url']); $search_res[$i][5] = $row['size']; $search_res[$i][6] = $row['date']; $text_array = split("\|",str_replace(" ","",$row['text'])); $w = 0; foreach ($text_array as $string) { if (preg_match($pattern_match, $string)) { $w ++; if ($w > $config['result_count_str']) continue; $search_res[$i][2] .= " ".preg_replace($pattern_replace,"\\1",$string)." "; } } $search_res[$i][2] = trim($search_res[$i][2]); $i++; } /* check isset result */ if (count($search_res) > 0) { /* sort by relevantnost */ function relevance($a, $b) { return strcmp($b['rel'],$a['rel']); } usort($search_res, "relevance"); $count_result = count($search_res); $print_result = 1; } else $print_error = 1; } else { /* no found result */ $print_error = 1; } } /* read header and footer */ $header_tpl = "./tpl/header.tpl"; $footer_tpl = "./tpl/footer.tpl"; $fp_header = fopen($header_tpl, "r"); $header_content = fread($fp_header, filesize($header_tpl)); fclose($fp_header); $fp_footer = fopen($footer_tpl, "r"); $footer_content = fread($fp_footer, filesize($footer_tpl)); fclose($fp_footer); /* url */ $search_url = $config['site_addr'].chr(47).$config['folder'].chr(47); /* print header */ echo $header_content; /* include and print quick search form */ include("./form.php"); /* if isset error -> print error */ if ($print_error == 1) { $count_result = 0; echo "

".$config['label_error_found'].htmlspecialchars(" \"{$page_query}\"")."

"; } elseif ($print_min == 1) { $count_result = 0; echo "

".$config['label_error_min']."

"; } if ($_GET['w'] == "0" && isset($_GET['q'])) { mysql_query("INSERT INTO `{$system['prefix']}_query` VALUES('',NOW(),'{$page_query}','{$count_result}','{$_SERVER['HTTP_REFERER']}','{$ip_addr}')"); } /* if isset result -> print result */ if ($print_result == 1) { echo "


"; $i = 0; $rec = record_on_page($count_result, $result_on_page, $_GET['p']); reset($search_res); /* print result */ while (list(, $value) = each($search_res)) { $i++; if ($i < $rec['recstart'] || $i > ($rec['recstart'] + $rec['reclimit'])) continue; echo "

"; if ($config['result_title'] == "1") { if (!$value[1]) $value[1] = $value[3]; $link = "{$value[1]}"; } else { $link = $link = "{$value[3]}"; } if ($config['result_titletop'] == "1") { echo $link."
"; } if ($value[2]) echo "".$value[2].""; $details = array(); if ($config['result_url'] == "1" || $config['result_date'] == "1" || $config['result_date'] == "1") { if ($config['result_url'] == "1") $details[] = $value[4]; if ($config['result_size'] == "1") $details[] = $value[5]; if ($config['result_date'] == "1") $details[] = $value[6]; echo "
".join(" - ", $details).""; } if ($config['result_titletop'] == "0") echo "
".$link; } /* esli bolshe chem 1 starnica */ if ($rec['reclimit'] < $count_result) { echo echo_on_page($rec, "{$search_url}?q=".urlencode($page_query)."&w=1&p="); } } /* print footer */ echo $footer_content; ?>




© 2009 Daughters of Miriam Center / The Gallen Institute
All RIghts Reserved. Reproduction in whole or in part without permission is prohibited.

Proudly Serving the Senior Jewish Communtity of Northern New Jersey and the New York / New Jersey Metrpolitan Area

Accredited by the Joint Commission on Accreditation of Healthcare Organizations (JCAHO)

Daughters of Miriam Center/The Gallen Institute is a Beneficiary Agency of UJA Federation of Northern NJ

To adjust the size of the font as it appears on your screen, use the text size function under VIEW on your toolbar.

Daughters of Miriam Center / The Gallen Institute
P.O. Box 2698 | 155 Hazel Street | Clifton, NJ 07015-2698