From: Sergey Kartashoff Date: Sat, 15 Sep 2001 12:20:37 +0000 (+0000) Subject: A bug fixed when trying to return NULL strings. X-Git-Tag: PRE_SUBST_Z_MACROS~101 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55d84825c1f8c0e7ee878e3949b1820207fb553a;p=php A bug fixed when trying to return NULL strings. Added a new example of building search frontend based on mnoGoSearch extension. @- A bug fixed when tryint to return NULL strings. @ Added a new example of building search frontend based on mnoGoSearch @ extension. --- diff --git a/ext/mnogosearch/index.php b/ext/mnogosearch/index.php new file mode 100644 index 0000000000..308cae2504 --- /dev/null +++ b/ext/mnogosearch/index.php @@ -0,0 +1,907 @@ + + +, + * mnoGoSearch Developers Team + */ + +if (!extension_loaded('mnogosearch')) { + print "This script requires PHP4.0.5+ with mnoGoSearch extension"; + exit; +} + +// maximal page number to view +$MAX_NP=1000; + +// maximum results per page +$MAX_PS=100; + +// (optional) Enable autowild feature for url limits +// 'yes' - default value, can be 'yes' or 'no' +// $auto_wild='yes'; + +/* variables section */ + +$dbaddr='mysql://udm:udm@/udm/'; +$dbmode='single'; + +$localcharset='koi8-r'; +$phrase=$cache=$crosswords='no'; +$ispelluseprefixes=$trackquery='no'; +$spell_host=$vardir=$datadir=''; +$ispellmode='text'; +$affix_file['en']='/opt/udm/ispell/en.aff'; +// $affix_file['ru']='/opt/udm/ispell/ru.aff'; +$spell_file['en']='/opt/udm/ispell/en.dict'; +// $spell_file['ru']='/opt/udm/ispell/ru.dict'; +$stopwordtable_arr[]='stopword'; +// $stopwordfile_arr[]='stopwords.txt'; +$minwordlength=1; +$maxwordlength=32; + +/* initialisation section */ + +$self=$PHP_SELF; + +if ($ps=="") $ps=20; +if ($np=="") $np=0; +if ($o=="") $o=0; + +if (($dt!='back') && ($dt!='er') && ($dt!='range')) $dt='back'; +if ($dp=="") $dp=0; +if (($dx!=0) && ($dx!=-1) && ($dx!=1)) $dx=0; +if ($dy<1970) $dy=1970; +if (($dm<0) || ($dm>11)) $dm=0; +if (($dd<=0) || ($dd>31)) $dd="01"; + +$db=urldecode($db); +$de=urldecode($de); + +if ($db=="") $db='01/01/1970'; +if ($de=="") $de='31/12/2020'; + +if (isset($q)) { + $q=urldecode($q); + $have_query_flag=1; +} else { + $have_query_flag=0; +} + +$ul=urldecode($ul); +$tag=urldecode($t); +$lang=urldecode($lang); + +$query_orig=$q; + +if (isset($CHARSET_SAVED_QUERY_STRING)) { + $q_local=urldecode($CHARSET_SAVED_QUERY_STRING); + if (preg_match('/q=([^&]*)\&/',$q_local,$param)) { + $q_local=urlencode($param[1]); + } elseif (preg_match('/q=(.*)$/',$q_local,$param)) { + $q_local=urlencode($param[1]); + } else { + $q_local=urlencode($q); + } +} else { + $q_local=urlencode($q); +} + +$ul_local=urlencode($ul); +$t_local=urlencode($tag); +$db_local=urlencode($db); +$de_local=urlencode($de); +$lang_local=urlencode($lang); + +if (($MAX_NP > 0) && ($np>$MAX_NP)) $np=$MAX_NP; +if (($MAX_PS > 0) && ($ps>$MAX_PS)) $ps=$MAX_PS; + +// ----------------------------------------------- +// print_bottom() +// ----------------------------------------------- +function print_bottom(){ + print ("
\n"); + print ("Powered by mnoGoSearch
\n"); + print ("

\n"); +} + + +// ----------------------------------------------- +// print_error_local($str) +// ----------------------------------------------- +function print_error_local($str){ + print ("

An error occured!\n"); + print ("

$str

\n"); + print_bottom(); + exit; +} + +// ----------------------------------------------- +// exit_local() +// ----------------------------------------------- +function exit_local($print_err = 1) { + drop_temp_table($print_err); + exit; +} + +// ----------------------------------------------- +// format_lastmod($lastmod) +// ----------------------------------------------- +function format_lastmod($lastmod) { + $temp=$lastmod; + if (!$temp) $temp = 'undefined'; + else $temp = strftime('%a, %d %b %Y %H:%M:%S %Z',$temp); + + return $temp; +} + +// ----------------------------------------------- +// format_dp($dp) +// ----------------------------------------------- +function format_dp($dp) { + $result=0; + + while ($dp != '') { + if (preg_match('/^([\-\+]?\d+)([sMhdmy]?)/',$dp,$param)) { + switch ($param[2]) { + case 's': $multiplier=1; break; + case 'M': $multiplier=60; break; + case 'h': $multiplier=3600; break; + case 'd': $multiplier=3600*24; break; + case 'm': $multiplier=3600*24*31; break; + case 'y': $multiplier=3600*24*365; break; + default: $multiplier=1; + } + + $result += $param[1]*$multiplier; + $dp=preg_replace("/^[\-\+]?\d+$param[2]/",'',$dp); + } else { + return 0; + } + } + + return $result; +} + +// ----------------------------------------------- +// format_userdate($date) +// ----------------------------------------------- +function format_userdate($date) { + $result=0; + + if (preg_match('/^(\d+)\/(\d+)\/(\d+)$/',$date,$param)) { + $day=$param[1]; + $mon=$param[2]; + $year=$param[3]; + + $result=mktime(0,0,0,$mon,$day,$year); + } + + return $result; +} + +// ----------------------------------------------- +// ParseDocText($text) +// ----------------------------------------------- +function ParseDocText($text){ + global $all_words; + global $hlbeg, $hlend; + + $str=$text; + for ($i=0; $i\?\/\,\.]+)($word)/i","\\1$hlbeg\\2$hlend",$str); + $str = preg_replace("/^($word)/i","$hlbeg\\1$hlend",$str); + } + + return $str; +} + +// ----------------------------------------------- +// print_template($t,$echo=1) +// ----------------------------------------------- +function print_template($t,$echo=1){ + global $templates, $udm_agent; + global $first_doc, $last_doc, $found, $query_orig, $error, $self; + global $nav, $wordinfo; + global $url, $ue, $o, $cat; + global $clones, $searchtime; + global $title, $rating, $desc, $contype, $lastmod, $docsize, $ndoc; + global $keyw, $text, $category; + global $crc, $Randoms, $rec_id, $DEBUG; + global $lang_url_translation, $phpver; + + + $str=$templates["$t"][$o]; + if ($str == '') $str=$templates["$t"][0]; + + $str=ereg_replace('\$f', "$first_doc", $str); + $str=ereg_replace('\$l', "$last_doc", $str); + $str=ereg_replace('\$t', "$found", $str); + $str=ereg_replace('\$A', $self, $str); + + $str=ereg_replace('\$Q', HtmlSpecialChars(StripSlashes($query_orig)), $str); + $str=ereg_replace('\$q', urlencode($query_orig), $str); + $str=eregi_replace('\$UE', $ue, $str); + + $str=ereg_replace('\$E', $error, $str); + $str=ereg_replace('\$W', $wordinfo, $str); + + $str=ereg_replace('\$V', $nav, $str); + + if ($lang_url_translation == 'yes') { + $nolangurl = ereg_replace("\.[a-z]{2}\.[a-z]{2,4}$", "", $url); + $str=ereg_replace('\$DU', $nolangurl, $str); + } else { + $str=ereg_replace('\$DU', $url, $str); + } + + $str=ereg_replace('\$DT', $title, $str); + $str=ereg_replace('\$DR', "$rating", $str); + $str=ereg_replace('\$DX', $text, $str); + $str=ereg_replace('\$DE', ($desc != '')?$desc:$text, $str); + $str=ereg_replace('\$DC', $contype, $str); + $str=ereg_replace('\$DM', $lastmod, $str); + $str=ereg_replace('\$DS', "$docsize", $str); + $str=ereg_replace('\$DN', "$ndoc", $str); + $str=ereg_replace('\$DD', $desc, $str); + $str=ereg_replace('\$DK', $keyw, $str); + $str=ereg_replace('\$SearchTime', "$searchtime", $str); + + if ($phpver >= 40006) { + if (ereg('\$CP',$str)) { + if ($temp_cp_arr=Udm_Cat_Path($udm_agent,$cat)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name "; + } + $str=ereg_replace('\$CP', $temp_cp, $str); + } else $str=ereg_replace('\$CP', '', $str); + } + + if (ereg('\$CS',$str)) { + if ($temp_cp_arr=Udm_Cat_List($udm_agent,$cat)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name
"; + } + $str=ereg_replace('\$CS', $temp_cp, $str); + } else $str=ereg_replace('\$CS', '', $str); + } + + if (ereg('\$DY',$str)) { + if ($temp_cp_arr=Udm_Cat_Path($udm_agent,$category)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name "; + } + $str=ereg_replace('\$DY', $temp_cp, $str); + } else $str=ereg_replace('\$DY', '', $str); + } + } else { + $str=ereg_replace('\$CP', '', $str); + $str=ereg_replace('\$CS', '', $str); + $str=ereg_replace('\$DY', '', $str); + } + + $sub=$str; + while($sub=strstr($sub,'$r')){ + $sub=substr($sub,2); + $pos=0; + $num=''; + + while(($sub[$pos]>='0')&&($sub[$pos]<='9')){ + $num.=$sub[$pos++]; + } + + $str=ereg_replace('\$r'.$num, ''.$Randoms[$num], $str); + } + +// if (strstr($str,'$CL')&&($t=='res')) { +// if (strtolower($clones) == 'no') { +// $str=ereg_replace('\$CL', '', $str); +// } elseif ($crc<>'') { +// } + $str=ereg_replace('\$CL', $clon, $str); +// } + + if($echo) echo $str; else return $str; +} + +// ----------------------------------------------- +// make_nav($query_orig) +// ----------------------------------------------- +function make_nav($query_orig){ + global $found,$np,$isnext,$ps,$tag,$ul,$self,$o,$m,$cat; + global $dt, $dp, $dx, $dm, $dy, $dd, $db, $de, $lang, $wm, $wf; + global $q_local,$ul_local,$t_local,$db_local,$de_local,$lang_local; + + if($np>0){ + $prevp=$np-1; + $prev_href="$self?q=$q_local&np=$prevp&m=$m". + ($ps==20?'':"&ps=$ps"). + ($tag==''?'':"&t=$t_local"). + ($ul==''?'':"&ul=$ul_local"). + ($wm==''?'':"&wm=$wm"). + ($wf==''?'':"&wf=$wf"). + (!$o?'':"&o=$o"). + ($dt=='back'?'':"&dt=$dt"). + (!$dp?'':"&dp=$dp"). + (!$dx?'':"&dx=$dx"). + ($dd=='01'?'':"&dd=$dd"). + (!$dm?'':"&dm=$dm"). + ($dy=='1970'?'':"&dy=$dy"). + ($db=='01/01/1970'?'':"&db=$db_local"). + ($de=='31/12/2020'?'':"&de=$de_local"). + ($cat==''?'':"&cat=$cat"). + ($lang==''?'':"&lang=$lang_local"); + + $nav_left="Prev\n"; + } elseif ($np==0) { + $nav_left="Prev\n"; + } + + if($isnext==1) { + $nextp=$np+1; + $next_href="$self?q=$q_local&np=$nextp&m=$m". + ($ps==20?'':"&ps=$ps"). + ($tag==''?'':"&t=$t_local"). + ($ul==''?'':"&ul=$ul_local"). + ($wm==''?'':"&wm=$wm"). + ($wf==''?'':"&wf=$wf"). + (!$o?'':"&o=$o"). + ($dt=='back'?'':"&dt=$dt"). + (!$dp?'':"&dp=$dp"). + (!$dx?'':"&dx=$dx"). + ($dd=='01'?'':"&dd=$dd"). + (!$dm?'':"&dm=$dm"). + ($dy=='1970'?'':"&dy=$dy"). + ($db=='01/01/1970'?'':"&db=$db_local"). + ($de=='31/12/2020'?'':"&de=$de_local"). + ($cat==''?'':"&cat=$cat"). + ($lang==''?'':"&lang=$lang_local"); + + $nav_right="Next\n"; + } else { + $nav_right="Next\n"; + } + + $nav_bar0='$NP'; + $nav_bar1='$NP'; + + $tp=ceil($found/$ps); + + $cp=$np+1; + + if ($cp>5) { + $lp=$cp-5; + } else { + $lp=1; + } + + $rp=$lp+10-1; + if ($rp>$tp) { + $rp=$tp; + $lp=$rp-10+1; + if ($lp<1) $lp=1; + } + + + if ($lp!=$rp) { + for ($i=$lp; $i<=$rp;$i++) { + $realp=$i-1; + + if ($i==$cp) { + $nav_bar=$nav_bar.$nav_bar0; + } else { + $nav_bar=$nav_bar.$nav_bar1; + } + + $href="$self?q=$q_local&np=$realp&m=$m". + ($ps==20?'':"&ps=$ps"). + ($tag==''?'':"&t=$t_local"). + ($ul==''?'':"&ul=$ul_local"). + ($wm==''?'':"&wm=$wm"). + ($wf==''?'':"&wf=$wf"). + (!$o?'':"&o=$o"). + ($dt=='back'?'':"&dt=$dt"). + (!$dp?'':"&dp=$dp"). + (!$dx?'':"&dx=$dx"). + ($dd=='01'?'':"&dd=$dd"). + (!$dm?'':"&dm=$dm"). + ($dy=='1970'?'':"&dy=$dy"). + ($db=='01/01/1970'?'':"&db=$db_local"). + ($de=='31/12/2020'?'':"&de=$de_local"). + ($cat==''?'':"&cat=$cat"). + ($lang==''?'':"&lang=$lang_local"); + + $nav_bar=ereg_replace('\$NP',"$i",$nav_bar); + $nav_bar=ereg_replace('\$NH',"$href",$nav_bar); + } + + $nav="$nav_left $nav_bar $nav_right
\n"; + } elseif ($found) { + $nav="$nav_left $nav_right
\n"; + } + + return $nav; +} + +// ----------------------------------------------- +// M A I N +// ----------------------------------------------- + + if (preg_match("/^(\d+)\.(\d+)\.(\d+)/",phpversion(),$param)) { + $phpver=$param[1]; + if ($param[2] < 9) { + $phpver .= "0$param[2]"; + } else { + $phpver .= "$param[2]"; + } + if ($param[3] < 9) { + $phpver .= "0$param[3]"; + } else { + $phpver .= "$param[3]"; + } + } else { + print "Cannot determine php version: ".phpversion()."\n"; + exit; + } + + if ($phpver >= 40006) { + if ($temp_cp_arr=Udm_Cat_Path($udm_agent,$cat)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name "; + } + $t_CP=$temp_cp; + } + + if ($temp_cp_arr=Udm_Cat_List($udm_agent,$cat)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name
"; + } + $t_CS=$temp_cp; + } + + if ($temp_cp_arr=Udm_Cat_Path($udm_agent,$category)) { + reset($temp_cp_arr); + $temp_cp=''; + for ($i=0; $i$cp_name "; + } + $t_DY=$temp_cp; + } + } + + $have_spell_flag=0; + + $udm_agent=Udm_Alloc_Agent($dbaddr,$dbmode); + + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_PAGE_SIZE,$ps); + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_PAGE_NUM,$np); + + $trackquery=strtolower($trackquery); + if ($trackquery == 'yes') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_TRACK_MODE,UDM_TRACK_ENABLED); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_TRACK_MODE,UDM_TRACK_DISABLED); + } + + $phrase=strtolower($phrase); + if ($phrase == 'yes') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_PHRASE_MODE,UDM_PHRASE_ENABLED); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_PHRASE_MODE,UDM_PHRASE_DISABLED); + } + + $cache=strtolower($cache); + if ($cache == 'yes') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_CACHE_MODE,UDM_CACHE_ENABLED); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_CACHE_MODE,UDM_CACHE_DISABLED); + } + + $ispelluseprefixes=strtolower($ispelluseprefixes); + if ($ispelluseprefixes == 'yes') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_ISPELL_PREFIXES,UDM_PREFIXES_ENABLED); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_ISPELL_PREFIXES,UDM_PREFIXES_DISABLED); + } + + if (Udm_Api_Version() >= 30111) { + $crosswords=strtolower($crosswords); + if ($crosswords == 'yes') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_CROSS_WORDS,UDM_CROSS_WORDS_ENABLED); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_CROSS_WORDS,UDM_CROSS_WORDS_DISABLED); + } + } + + if ($localcharset != '') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_CHARSET,$localcharset); + } + + for ($i=0; $i < count($stopwordtable_arr); $i++) { + if ($stopwordtable_arr[$i] != '') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_STOPTABLE,$stopwordtable_arr[$i]); + } + } + + for ($i=0; $i < count($stopwordfile_arr); $i++) { + if ($stopwordfile_arr[$i] != '') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_STOPFILE,$stopwordfile_arr[$i]); + } + } + + if ($m=='any') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_SEARCH_MODE,UDM_MODE_ANY); + } elseif ($m=='all') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_SEARCH_MODE,UDM_MODE_ALL); + } elseif ($m=='bool') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_SEARCH_MODE,UDM_MODE_BOOL); + } elseif ($m=='phrase') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_SEARCH_MODE,UDM_MODE_PHRASE); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_SEARCH_MODE,UDM_MODE_ALL); + } + + if ($wm=='wrd') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WORD_MATCH,UDM_MATCH_WORD); + } elseif ($wm=='beg') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WORD_MATCH,UDM_MATCH_BEGIN); + } elseif ($wm=='end') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WORD_MATCH,UDM_MATCH_END); + } elseif ($wm=='sub') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WORD_MATCH,UDM_MATCH_SUBSTR); + } else { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WORD_MATCH,UDM_MATCH_WORD); + } + + if ($minwordlength >= 0) { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_MIN_WORD_LEN,$minwordlength); + } + + if ($maxwordlength >= 0) { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_MAX_WORD_LEN,$maxwordlength); + } + + if ($phpver >= 40007) { + if ($vardir != '') Udm_Set_Agent_Param($udm_agent,UDM_PARAM_VARDIR,$vardir); + if ($datadir != '') Udm_Set_Agent_Param($udm_agent,UDM_PARAM_VARDIR,$datadir); + } + + if ($wf != '') { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_WEIGHT_FACTOR,$wf); + } + + if ($ul != '') { + $auto_wild=strtolower($auto_wild); + if (($auto_wild == 'yes') || + ($auto_wild == '')) { + if ((substr($ul,0,7) == 'http://') || + (substr($ul,0,8) == 'https://') || + (substr($ul,0,7) == 'news://') || + (substr($ul,0,6) == 'ftp://')) { + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_URL,"$ul%"); + } else { + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_URL,"%$ul%"); + } + } else { + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_URL,$ul); + } + } + + if ($tag != '') Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_TAG,$tag); + if ($cat != '') Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_CAT,$cat); + if ($lang != '')Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_LANG,$lang); + + if (($dt == 'back') && ($dp != '0')) { + $recent_time=format_dp($dp); + if ($recent_time != 0) { + $dl=time()-$recent_time; + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_DATE,">$dl"); + } + } elseif ($dt=='er') { + $recent_time=mktime(0,0,0,($dm+1),$dd,$dy); + if ($dx == -1) { + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_DATE,"<$recent_time"); + } elseif ($dx == 1) { + Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_DATE,">$recent_time"); + } + } elseif ($dt=='range') { + $begin_time=format_userdate($db); + if ($begin_time) Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_DATE,">$begin_time"); + + $end_time=format_userdate($de); + if ($end_time) Udm_Add_Search_Limit($udm_agent,UDM_LIMIT_DATE,"<$end_time"); + } + +// if ($have_query_flag) $q=ParseQ($q); + +?> + + + + mnoGoSearch: <? echo HtmlSpecialChars(StripSlashes($query_orig)); ?> + + + +
+ +
+ + + + + + + + + + + + + +
+
+ +Search for: +
+ +Results per page: + + +Match: + + + +Search for: + + +
+ +Search through: + + +in: + + +Language: + + +Restrict search: + + +
+ + + + + + + + + + + + + + +
+Limit results to pages published within a specified period of time.
+(Please select only one option) +
> +
> + + +or on + + + +, + +
> + +Between + +and + +
+ +
+
+
+ + += 30112) { + if (! Udm_Load_Ispell_Data($udm_agent,UDM_ISPELL_TYPE_SERVER,$spell_host,'',1)) { + print_error_local("Error loading ispell data from server $spell_host"); + } else $have_spell_flag=1; + } + } elseif ($ispellmode == 'text') { + reset($affix_file); + while (list($t_lang,$file)=each($affix_file)) { + if (! Udm_Load_Ispell_Data($udm_agent,UDM_ISPELL_TYPE_AFFIX,$t_lang,$file,0)) { + print_error_local("Error loading ispell data from file"); + } else $have_spell_flag=1; + + $temp=$spell_file[$t_lang]; + for ($i=0; $iYou should give at least one word to search for.\n"); + print_bottom(); + return; +} + +$res=Udm_Find($udm_agent,$q); + +if(($errno=Udm_Errno($udm_agent))>0){ + print_error_local(Udm_Error($udm_agent)); +} else { + $found=Udm_Get_Res_Param($res,UDM_PARAM_FOUND); + $rows=Udm_Get_Res_Param($res,UDM_PARAM_NUM_ROWS); + $wordinfo=Udm_Get_Res_Param($res,UDM_PARAM_WORDINFO); + $searchtime=Udm_Get_Res_Param($res,UDM_PARAM_SEARCHTIME); + $first_doc=Udm_Get_Res_Param($res,UDM_PARAM_FIRST_DOC); + $last_doc=Udm_Get_Res_Param($res,UDM_PARAM_LAST_DOC); + + if (!$found) { + print ("Search Time: $searchtime
Search results:\n"); + print ("$wordinfo
Sorry, but search returned no results.

\n"); + print ("Try to produce less restrictive search query.

\n"); + + print_bottom(); + return; + } + + $from=IntVal($np)*IntVal($ps); + $to=IntVal($np+1)*IntVal($ps); + + if($to>$found) $to=$found; + if (($from+$ps)<$found) $isnext=1; + $nav=make_nav($query_orig); + + print("Search Time: $searchtime
Search results: $wordinfo
\n"); + print("Displaying documents $first_doc-$last_doc of total $found found.\n"); + + for($i=0;$i<$rows;$i++){ + $ndoc=Udm_Get_Res_Field($res,$i,UDM_FIELD_ORDER); + $rating=Udm_Get_Res_Field($res,$i,UDM_FIELD_RATING); + $url=Udm_Get_Res_Field($res,$i,UDM_FIELD_URL); + $title=Udm_Get_Res_Field($res,$i,UDM_FIELD_TITLE); + $title=($title) ? htmlspecialChars($title):'No title'; + $text=htmlspecialChars(Udm_Get_Res_Field($res,$i,UDM_FIELD_TEXT)); + $contype=Udm_Get_Res_Field($res,$i,UDM_FIELD_CONTENT); + $docsize=Udm_Get_Res_Field($res,$i,UDM_FIELD_SIZE); + $lastmod=format_lastmod(Udm_Get_Res_Field($res,$i,UDM_FIELD_MODIFIED)); + $keyw=htmlspecialChars(Udm_Get_Res_Field($res,$i,UDM_FIELD_KEYWORDS)); + $desc=htmlspecialChars(Udm_Get_Res_Field($res,$i,UDM_FIELD_DESC)); + $crc=Udm_Get_Res_Field($res,$i,UDM_FIELD_CRC); + $rec_id=Udm_Get_Res_Field($res,$i,UDM_FIELD_URLID); + + if ($phpver >= 40006) { + $category=Udm_Get_Res_Field($res,$i,UDM_FIELD_CATEGORY); + } else { + $category=''; + } + + print ("
$ndoc.$title\n"); + print ("[$rating]
\n"); + print (($desc != '')?$desc:$text."...
$t_DY
  • \n"); + print ("$url\n"); + print ("($contype) $lastmod, $docsize bytes
\n"); + } + + print("
$nav
\n"); + print_bottom(); + + // Free result + Udm_Free_Res($res); +} + + if ($have_spell_flag) Udm_Free_Ispell_Data($udm_agent); + Udm_Free_Agent($udm_agent); +?> diff --git a/ext/mnogosearch/php_mnogo.c b/ext/mnogosearch/php_mnogo.c index 5460c8a115..a1f7083af4 100644 --- a/ext/mnogosearch/php_mnogo.c +++ b/ext/mnogosearch/php_mnogo.c @@ -910,27 +910,27 @@ DLEXPORT PHP_FUNCTION(udm_get_res_field) if(rownum_rows){ switch(field){ case UDM_FIELD_URL: - RETURN_STRING((Res->Doc[row].url),1); + RETURN_STRING((Res->Doc[row].url)?(Res->Doc[row].url):"",1); break; case UDM_FIELD_CONTENT: - RETURN_STRING((Res->Doc[row].content_type),1); + RETURN_STRING((Res->Doc[row].content_type)?(Res->Doc[row].content_type):"",1); break; case UDM_FIELD_TITLE: - RETURN_STRING((Res->Doc[row].title),1); + RETURN_STRING((Res->Doc[row].title)?(Res->Doc[row].title):"",1); break; case UDM_FIELD_KEYWORDS: - RETURN_STRING((Res->Doc[row].keywords),1); + RETURN_STRING((Res->Doc[row].keywords)?(Res->Doc[row].keywords):"",1); break; case UDM_FIELD_DESC: - RETURN_STRING((Res->Doc[row].description),1); + RETURN_STRING((Res->Doc[row].description)?(Res->Doc[row].description):"",1); break; case UDM_FIELD_TEXT: - RETURN_STRING((Res->Doc[row].text),1); + RETURN_STRING((Res->Doc[row].text)?(Res->Doc[row].text):"",1); break; case UDM_FIELD_SIZE: @@ -958,7 +958,7 @@ DLEXPORT PHP_FUNCTION(udm_get_res_field) break; case UDM_FIELD_CATEGORY: - RETURN_STRING((Res->Doc[row].category),1); + RETURN_STRING((Res->Doc[row].category)?(Res->Doc[row].category):"",1); break; default: @@ -1004,7 +1004,7 @@ DLEXPORT PHP_FUNCTION(udm_get_res_param) break; case UDM_PARAM_WORDINFO: - RETURN_STRING(Res->wordinfo,1); + RETURN_STRING((Res->wordinfo)?(Res->wordinfo):"",1); break; case UDM_PARAM_SEARCHTIME: @@ -1116,7 +1116,7 @@ DLEXPORT PHP_FUNCTION(udm_error) break; } ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, -1, "mnoGoSearch-Agent", le_link); - RETURN_STRING(UdmDBErrorMsg(Agent->db),1); + RETURN_STRING((UdmDBErrorMsg(Agent->db))?(UdmDBErrorMsg(Agent->db)):"",1); } /* }}} */ diff --git a/ext/mnogosearch/test.php b/ext/mnogosearch/test.php deleted file mode 100644 index 1cccc1d944..0000000000 --- a/ext/mnogosearch/test.php +++ /dev/null @@ -1,138 +0,0 @@ - - - - - -
- - -
- -
-
-\n");
-		exit();
-	}
-	
-// Stage 1: allocate UdmSearch agent, set DBAddr and DBMode
-// DBMode is optional, "single" by default
-
-	$udm=Udm_Alloc_Agent("mysql://udm:udm@localhost/udm/",'single');	
-	
-	if (Udm_Api_Version() >= 30111) {
-		print  "Total number of urls in database: ".Udm_Get_Doc_Count($udm)."
\n"; - } - -// Stage 2: set search parameters - - $page_size=10; - $page_number=0; - - Udm_Set_Agent_Param($udm,UDM_PARAM_PAGE_SIZE,$page_size); - Udm_Set_Agent_Param($udm,UDM_PARAM_PAGE_NUM,$page_number); - Udm_Set_Agent_Param($udm,UDM_PARAM_SEARCH_MODE,UDM_MODE_BOOL); - Udm_Set_Agent_Param($udm,UDM_PARAM_CACHE_MODE,UDM_CACHE_DISABLED); - Udm_Set_Agent_Param($udm,UDM_PARAM_TRACK_MODE,UDM_TRACK_DISABLED); - Udm_Set_Agent_Param($udm,UDM_PARAM_CHARSET,"koi8-r"); -// Udm_Set_Agent_Param($udm,UDM_PARAM_STOPTABLE,"stopword"); -// Udm_Set_Agent_Param($udm,UDM_PARAM_STOPFILE,"stop.txt"); - Udm_Set_Agent_Param($udm,UDM_PARAM_WEIGHT_FACTOR,"F9421"); - Udm_Set_Agent_Param($udm,UDM_PARAM_WORD_MATCH,UDM_MATCH_WORD); - Udm_Set_Agent_Param($udm,UDM_PARAM_PHRASE_MODE,UDM_PHRASE_DISABLED); - Udm_Set_Agent_Param($udm,UDM_PARAM_MIN_WORD_LEN,2); - Udm_Set_Agent_Param($udm,UDM_PARAM_MAX_WORD_LEN,16); - Udm_Set_Agent_Param($udm,UDM_PARAM_PREFIX,UDM_PREFIX_DISABLED); - Udm_Set_Agent_Param($udm,UDM_PARAM_VARDIR,"/opt/mnogo/install/var"); - - if (Udm_Api_Version() >= 30111) { - Udm_Set_Agent_Param($udm,UDM_PARAM_CROSS_WORDS,UDM_CROSS_WORDS_DISABLED); - } - -// if (! Udm_Load_Ispell_Data($udm,UDM_ISPELL_TYPE_DB,'','',1)) { -// printf("Error #%d: '%s'\n",Udm_Errno($udm),Udm_Error($udm)); -// exit; -// } - -// if ((! Udm_Load_Ispell_Data($udm,UDM_ISPELL_TYPE_AFFIX,'en','/opt/udm/ispell/en.aff',0)) || -// (! Udm_Load_Ispell_Data($udm,UDM_ISPELL_TYPE_SPELL,'en','/opt/udm/ispell/en.dict',1))) { -// printf("Error loading ispell data from files
\n"); -// exit; -// } - -// if (! Udm_Load_Ispell_Data($udm,UDM_ISPELL_TYPE_SERVER,'','',1)) { -// printf("Error loading ispell data from server
\n"); -// exit; -// } - -// Stage 3: add search limits -// Udm_Add_Search_Limit($udm,UDM_LIMIT_URL,"http://www.mydomain.com/%"); -// Udm_Add_Search_Limit($udm,UDM_LIMIT_TAG,"01"); -// Udm_Add_Search_Limit($udm,UDM_LIMIT_CAT,"01"); -// Udm_Add_Search_Limit($udm,UDM_LIMIT_LANG,"en"); -// Udm_Add_Search_Limit($udm,UDM_LIMIT_DATE,"<908012006"); - -// Udm_Clear_Search_Limits($udm); - -// Stage 4: perform search - - $res=Udm_Find($udm,$q); - -// Stage 5: display results - - // Check error code - if(($errno=Udm_Errno($udm))>0){ - // Display error message - printf("Error #%d: '%s'\n",$errno,Udm_Error($udm)); - }else{ - $first=$page_size*$page_number+1; - - // Get result parameters - $total=Udm_Get_Res_Param($res,UDM_PARAM_FOUND); - $rows=Udm_Get_Res_Param($res,UDM_PARAM_NUM_ROWS); - $wordinfo=Udm_Get_Res_Param($res,UDM_PARAM_WORDINFO); - $searchtime=Udm_Get_Res_Param($res,UDM_PARAM_SEARCHTIME); - $first_doc=Udm_Get_Res_Param($res,UDM_PARAM_FIRST_DOC); - $last_doc=Udm_Get_Res_Param($res,UDM_PARAM_LAST_DOC); - - printf("Searchtime: ".$searchtime."\n\n"); - - printf("Documents %d-%d from %d total found; %s\n\n", - $first_doc,$last_doc,$total,$wordinfo); - - // Fetch all rows - for($i=0;$i<$rows;$i++){ - printf("%3d. %s\n",$first+$i,Udm_Get_Res_Field($res,$i,UDM_FIELD_URL)); - printf(" ORDER : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_ORDER)); - printf(" CONT : %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_CONTENT))); - printf(" TITLE: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_TITLE))); - printf(" KEYWORDS: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_KEYWORDS))); - printf(" DESC: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_DESC))); - printf(" TEXT: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_TEXT))); - printf(" SIZE : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_SIZE)); - printf(" MODIFIED : %s\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_MODIFIED)); - printf(" URLID : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_URLID)); - printf(" RATING : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_RATING)); - printf(" CRC : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_CRC)); - printf("---------\n"); - } - - // Free result - Udm_Free_Res($res); - } - -//Stage 6: free ispell data if loaded before -// Udm_Free_Ispell_Data($udm); - -//Stage 7: free UdmSearch agent - - Udm_Free_Agent($udm); -?> - -
- -