PDA

View Full Version : Search Query in Hebrew (not in vb)


zurih
09-07-2005, 09:18 AM
Hi!
I'm having a problem solving this one.
I installed a cms software based on php/mysql. In oroginal it was based on english, and I translated everything to Hebrew.

Everything works fine, but the search queries.
When I search something (a download, an articles, in forums etc) it doesnt find nothing. If it is in english it works perfect.

Now the thing is that when i run a seach with characters like the attached picture (that is based on windows-1252) >> it works.
those thing are 3 hebrew characters.

Hope I was understandable.

Here is the query.php code:


<?php
$tmpl->assign('lang', $lang);
$tmpl->assign('redir', redir());
$q = $_GET['q'];
if(strlen($q)<2) {$q = ""; }
if ($q == "") {
$EOUT = msg("searchsite", "searchsite_nochara", str_replace("__URL__", $_SERVER['HTTP_REFERER'], $lang['redirect']), $_SERVER['HTTP_REFERER']);
$NOOUT = 1;
}
$search_type = 'REGEXP';
$search_prefix = '';
$search_type = ($_GET['regexp'] == 1) ? 'REGEXP' : 'LIKE';
$search_prefix = ($_GET['regexp'] == 1) ? '' : '%';
$pattern_or = @explode('or', strtolower($q));
$pattern_tmp = "";
$p_and_array = array();
foreach ($pattern_or as $part) {
$pattern_and = @explode('and', strtolower($part));
$sub_pattern = array();
foreach ($pattern_and as $sub_part) {
$sub_part = trim($sub_part);
if($_GET['search_news']==1){
$sub_pattern[] = "
(
title $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
text $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
textmore $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}
if($_GET['search_articles']==1) {
$sub_pattern_a[] = "
(
title $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
content $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}
if($_GET['search_downloads']==1 || $_GET['search_links']==1) {
$sub_pattern_b[] = "
(
title $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
text $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}
if($_GET['search_faq']==1) {
$sub_pattern_d[] = "
(
faq $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
answer $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}
if($_GET['search_static']==1) {
$sub_pattern_e[] = "
(
title $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
content $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}

if($_GET['search_gallery']==1) {
$sub_pattern_f[] = "
(
title $search_type '" . $search_prefix . $sub_part . $search_prefix . "' OR
descr $search_type '" . $search_prefix . $sub_part . $search_prefix . "'
)";
}
}
$pattern_tmp = @implode(' AND ', $sub_pattern);
$pattern_tmp_a = @implode(' AND ', $sub_pattern_a);
$pattern_tmp_b = @implode(' AND ', $sub_pattern_b);
$pattern_tmp_c = @implode(' AND ', $sub_pattern_b);
$pattern_tmp_d = @implode(' AND ', $sub_pattern_d);
$pattern_tmp_e = @implode(' AND ', $sub_pattern_e);
$pattern_tmp_f = @implode(' AND ', $sub_pattern_f);
$p_and_array[] = $pattern_tmp;
$p_and_array_a[] = $pattern_tmp_a;
$p_and_array_b[] = $pattern_tmp_b;
$p_and_array_c[] = $pattern_tmp_c;
$p_and_array_d[] = $pattern_tmp_d;
$p_and_array_e[] = $pattern_tmp_e;
$p_and_array_f[] = $pattern_tmp_f;
}
$pattern = @implode(' OR ', $p_and_array);
$pattern_a = @implode(' OR ', $p_and_array_a);
$pattern_b = @implode(' OR ', $p_and_array_b);
$pattern_c = @implode(' OR ', $p_and_array_c);
$pattern_d = @implode(' OR ', $p_and_array_d);
$pattern_e = @implode(' OR ', $p_and_array_e);
$pattern_f = @implode(' OR ', $p_and_array_f);
$limit = ($_REQUEST['pp']=="") ? 15 : $_REQUEST['pp'];
if($_GET['search_gallery']==1){
$galleryitems = array();
$sql = $db->Query("SELECT id FROM ".PREFIX."_gallery WHERE area = '$area' AND $pattern_f");
$count_gallery = $sql->numrows();
$tmpl->assign('count_gallery',$count_gallery);
$seiten = ceil($count_gallery / $limit);
$a = prepage() * $limit - $limit;
if($count_gallery > $limit){
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?q=$q&amp;search_gallery=1&amp;p=query&amp;details=1&amp; pp=".$limit."&amp;page={s}\">{t}</a> "));
}
$sql = $db->Query("SELECT id,parent_id,title,descr FROM ".PREFIX."_gallery WHERE area = '$area' AND $pattern_f limit $a,$limit");
while($row = $sql->fetchrow()){
if(@strpos(strtolower($row->title), strtolower($q))>1){
$fundort = strip_tags($row->title);
} else {
$fundort = strip_tags($row->descr);
}
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$row->erg = $orte;
$row->erg_str = $fundort;
array_push($galleryitems,$row);
}
$tmpl->assign('galleryitems', $galleryitems);
}
if($_GET['search_faq']==1){
$faqitems = array();
$sql = $db->Query("SELECT id FROM ".PREFIX."_faq WHERE area = '$area' AND $pattern_d");
$count_faq = $sql->numrows();
$tmpl->assign('count_faq',$count_faq);
$seiten = ceil($count_faq / $limit);
$a = prepage() * $limit - $limit;
if($count_faq > $limit){
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?q=$q&amp;search_faq=1&amp;p=query&amp;details=1&amp;pp=".$limit."&amp;page={s}\">{t}</a> "));
}
$sql = $db->Query("SELECT id,parent_id,faq,answer FROM ".PREFIX."_faq WHERE area = '$area' AND $pattern_d limit $a,$limit");
while($row = $sql->fetchrow()){
if(@strpos(strtolower($row->faq), strtolower($q))>1){
$fundort = strip_tags($row->faq);
} else {
$fundort = strip_tags($row->answer);
}
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$row->erg = $orte;
$row->erg_str = $fundort;
array_push($faqitems,$row);
}
$tmpl->assign('faqitems', $faqitems);
}
if($_GET['search_static']==1){
$static_items = array();
$sql = "SELECT id FROM ".PREFIX."_static WHERE $pattern_e ORDER BY ctime $ascdesc";
$res = $db->Query($sql);
$count_static = $res->numrows();
$tmpl->assign('count_static',$count_static);
$seiten = ceil($count_static / $limit);
$a = prepage() * $limit - $limit;
$sql = "SELECT * FROM ".PREFIX."_static WHERE $pattern_e ORDER BY ctime $ascdesc";
$res = $db->Query($sql);
if($count_static > $limit){
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?q=$q&amp;search_static=1&amp;p=query&amp;details=1&amp;p p=".$limit."&amp;page={s}\">{t}</a> "));
}
while($row = $res->fetchrow()){
if(@strpos(strtolower($row->content), strtolower($q))>1){
$fundort = strip_tags($row->content);
} else {
$fundort = strip_tags($row->content);
}
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$row->erg = $orte;
$row->erg_str = $fundort;
array_push($static_items,$row);
}
$tmpl->assign('static_items', $static_items);
}
if($_GET['search_news']==1){
$newsitems = array();
$db_search = " && ( (cansearch='yes') AND $pattern )";
$sql = "SELECT newsid FROM ".PREFIX."_news WHERE
((area_id='$area' || allareas='yes') &&
((time_end>=".time().") ||
(time_end='1') ||
(time_end='0')) &&
(((ispublic='1')) &&
(time_start<=".time().") $db_search))
ORDER BY ntime $ascdesc";
$res = $db->Query($sql);
$count_news = $res->numrows();
$tmpl->assign('count_news',$count_news);
$seiten = ceil($count_news / $limit);
$a = prepage() * $limit - $limit;
$sql = "SELECT
area_id,
newscat,
uid,
newsid,
title,
text,
textmore,
time_start,
ntime
FROM ".PREFIX."_news WHERE
((area_id='$area' || allareas='yes') &&
((time_end>=".time().") ||
(time_end='1') ||
(time_end='0')) &&
(((ispublic='1')) &&
(time_start<=".time().") $db_search))
ORDER BY ntime $ascdesc limit $a,$limit";
$res = $db->Query($sql);
if($count_news > $limit){
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?q=$q&amp;search_news=1&amp;p=query&amp;details=1&amp;pp=".$limit."&amp;page={s}\">{t}</a> "));
}
while($row = $res->fetchrow()){
if(@strpos(strtolower($row->text), strtolower($q))>1){
$fundort = strip_tags($row->text);
} else {
$fundort = strip_tags($row->textmore);
}
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$row->erg = $orte;
$row->erg_str = $fundort;
array_push($newsitems,$row);
}
$tmpl->assign('newsitems', $newsitems);
}
if($_GET['search_articles']==1){
$articleitems = array();
$db_search = " && ( (cansearch='yes') AND $pattern_a )";
$sql = "
SELECT id FROM ".PREFIX."_articles WHERE
((area='$area' || allareas='yes') &&
((time_end>=".time().") ||
(time_end='1') ||
(time_end='0')) &&
(((active='1')) &&
(time_start<=".time().") &&
(showonpage='1') $db_search ))";
$res = $db->Query($sql);
$count_articles = $res->numrows();
$tmpl->assign('count_articles',$count_articles);
$seiten = ceil($count_articles / $limit);
$a = prepage() * $limit - $limit;
$sql = "
SELECT
id,
area,
type,
title,
content,
ctime
FROM ".PREFIX."_articles WHERE
((area='$area' || allareas='yes') &&
((time_end>=".time().") ||
(time_end='1') ||
(time_end='0')) &&
(((active='1')) &&
(time_start<=".time().") &&
(showonpage='1') $db_search ))
ORDER BY ctime limit $a,$limit";
$res = $db->Query($sql);
if($count_articles > $limit){
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?q=$q&amp;search_articles=1&amp;p=query&amp;details=1 &amp;pp=".$limit."&amp;page={s}\">{t}</a> "));
}
while($row = $res->fetchrow()){
if(@strpos(strtolower($row->content), strtolower($q))>1){
$fundort = strip_tags($row->content);
}
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$row->erg = $orte;
$row->erg_str = $fundort;
array_push($articleitems,$row);
}
$tmpl->assign('articleitems', $articleitems);
}
if($_GET['search_downloads']==1){
$group_ids = array();
if (@is_numeric(UID)) {
$queryfirst = "SELECT group_id_misc FROM " . PREFIX . "_user WHERE uid = " . UID;
$result = $db->Query($queryfirst);
$user = $result->fetchrow();
if($user->group_id_misc != ""){
$group_ids_pre = UGROUP . ";" . $user->group_id_misc;
$group_ids = @explode(";", $group_ids_pre);
} else {
$group_ids[] = UGROUP;
}
} else {
$group_ids[] = 2;
}
$downloads = array();
$sql = "SELECT ctime,title,text,area,id,catid FROM " . PREFIX . "_downloads WHERE $pattern_b limit 200";
$res = $db->Query($sql);
$num = $res->numrows();
while($item= $res->fetchrow()){
$query = $db->Query("SELECT group_id FROM " . PREFIX . "_downloadcat WHERE catid = '$item->catid'");
$row = $query->fetchrow();
$g_array = @explode(",", $row->group_id);
if (array_intersect($group_ids, $g_array)) {
$count_downloads += 1;
$fundort = strip_tags($item->text);
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$item->erg = $orte;
$item->erg_str = $fundort;
array_push($downloads, $item);
}

$tmpl->assign('count_downloads',$count_downloads);
$tmpl->assign('downloads', $downloads);
}
}
if($_GET['search_links']==1){
$group_ids = array();
if (@is_numeric(UID)) {
$queryfirst = "SELECT group_id_misc FROM " . PREFIX . "_user WHERE uid = " . UID;
$result = $db->Query($queryfirst);
$user = $result->fetchrow();
if($user->group_id_misc != ""){
$group_ids_pre = UGROUP . ";" . $user->group_id_misc;
$group_ids = @explode(";", $group_ids_pre);
} else {
$group_ids[] = UGROUP;
}
} else {
$group_ids[] = 2;
}
$links = array();
$sql = "SELECT ctime,title,text,area,id,catid FROM " . PREFIX . "_links WHERE $pattern_c limit 200";
$res = $db->Query($sql);
while($item= $res->fetchrow()){
$query = $db->Query("SELECT group_id FROM " . PREFIX . "_linkcat WHERE catid = '$item->catid'");
$row = $query->fetchrow();
$g_array = @explode(",", $row->group_id);
if (array_intersect($group_ids, $g_array)) {
$count_links += 1;
$fundort = strip_tags($item->text);
@eregi(".{0,35}" . $q . ".{0,35}", $fundort, $fo);
$orte = " ... ";
while (@list($key, $val) = @each($fo)) {
$orte .= $val . " ... ";}
$orte = @eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $orte);
$item->erg = $orte;
$item->erg_str = $fundort;
array_push($links, $item);
}
$tmpl->assign('count_links',$count_links);
$tmpl->assign('links', $links);
}
}
$countall = $count_links + $count_downloads + $count_articles + $count_news + $count_faq + $count_static + $count_gallery;
$countall_text = str_replace("__MATCHES__", $countall, $lang['search_result_matches_text']);
$tmpl->assign('numall', $countall);
$tmpl->assign('countall', $countall_text);
$tmpl->assign('q', $q);
$sname = simpletitle($lang['searchsite']);
$tmpl->assign("content", parsetrue("container/".container("news"), $lang['searchsite'], $tmpl->fetch("search/query.tpl")));
?>