Homepage Demos Overview Downloads Tutorials Reference
Credits

Tekkotsu_doc_2.2.2/newmat/http://cvs.tekkotsu.org/search.php

Go to the documentation of this file.
00001 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00002 <html>
00003   <head>
00004     <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
00005     <title>Search</title>
00006     <link href="doxygen.css" rel="stylesheet" type="text/css">
00007     <link rel="home" href="../index.html">
00008     <link rel="up" href="../index.html">
00009     <link rel="SHORTCUT ICON" href="favicon.ico">
00010   </head>
00011   <body>
00012     <!-- <img src="aibosmall.jpg" width=92 height=75 align=right> -->
00013     <table cellpadding="1" cellspacing="6" border="0"
00014            style="text-align: left; margin-left: auto; margin-right: auto;">
00015       <tbody>
00016         <tr>
00017           <!-- #Homepage# --> <td style="vertical-align: top;"><a target="_top" href="../../index.html">Homepage</a></td>
00018           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"></td>
00019           <!-- #Demos# --> <td style="vertical-align: top;"><a target="_top" href="../../Samples.html">Demos</a></td>
00020           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"></td>
00021           <!-- #Overview# --> <td style="vertical-align: top;"><a target="_top" href="../../Overview.html">Overview</a></td>
00022           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"></td>
00023           <!-- #Downloads# --> <td style="vertical-align: top;"><a target="_top" href="../../VersionHistory.html">Downloads</a></td>
00024           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"></td>
00025           <!-- #Tutorials# --> <td style="vertical-align: top;"><a target="_top" href="../../Tutorials.html">Tutorials</a></td>
00026           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"></td>
00027           <!-- #Reference# --> <td style="vertical-align: top;"><a target="_top" href="../index.html">Reference</a></td>
00028           <!-- #Bar# --> <td style="vertical-align: top; background-color: rgb(0, 0, 0);"><br></td>
00029           <!-- #Credits# --> <td style="vertical-align: top;"><a target="_top" href="../../Credits.html">Credits</a> </td>
00030         </tr>
00031       </tbody>
00032     </table>
00033 <table style="text-align: left; margin-left: auto; margin-right: auto; width: 700px;" border="0" cellspacing="2" cellpadding="2">
00034   <tbody>
00035     <tr>
00036       <td style="vertical-align: top;">
00037 <!-- Generated by Doxygen 1.4.0 -->
00038 <div class="qindex">  <form class="search" action="http://cvs.tekkotsu.org/search.php" method="get">
00039 <table border=0 class="qindex"><tr><td width="20%" align="center"><a class="qindex" href="main.html">Main&nbsp;Page</a></td>
00040 <td width="0px" bgcolor="000000"></td>
00041 <td valign="top" width="20%" align="left"><b>Classes: </b><center><a class="qindex" href="annotated.html">List</a>, <a class="qindex" href="classes.html">Index</a>, <a class="qindex" href="hierarchy.html">Hierarchy</a>, <a class="qindex" href="functions.html">Members</a></center></td>
00042 <td width="0px" bgcolor="000000"></td>
00043 <td valign="top" width="20%" align="left"><b>Namespaces: </b><center><a class="qindex" href="namespaces.html">List</a>, <a class="qindex" href="namespacemembers.html">Members</a></center></td>
00044 <td width="0px" bgcolor="000000"></td>
00045 <td valign="top" width="20%" align="left"><b>Files: </b><center><a class="qindex" href="files.html">List</a>, <a class="qindex" href="dirs.html">Directories</a>, <a class="qindex" href="globals.html">Members</a></center></td>
00046 <td width="0px" bgcolor="000000"></td>
00047 <td valign="top" width="20%" align="center"><hr><span class="searchHL"><u>S</u>earch&nbsp;</td>
00048 </tr></table></form>
00049 </div>
00050 
00051 <?php
00052 
00053 function search_results()
00054 {
00055   return "Search Results";
00056 }
00057 
00058 function matches_text($num)
00059 {
00060   if ($num==0)
00061   {
00062     return "Sorry, no documents matching your query.";
00063   }
00064   else if ($num==1)
00065   {
00066     return "Found <b>1</b> document matching your query.";
00067   }
00068   else // $num>1
00069   {
00070     return "Found <b>$num</b> documents matching your query. Showing best matches first.";
00071   }
00072 }
00073 
00074 function report_matches()
00075 {
00076   return "Matches: ";
00077 }
00078 
00079 function readInt($file)
00080 {
00081   $b1 = ord(fgetc($file)); $b2 = ord(fgetc($file));
00082   $b3 = ord(fgetc($file)); $b4 = ord(fgetc($file));
00083   return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
00084 }
00085 
00086 function readString($file)
00087 {
00088   $result="";
00089   while (ord($c=fgetc($file))) $result.=$c;
00090   return $result;
00091 }
00092 
00093 function readHeader($file)
00094 {
00095   $header =fgetc($file); $header.=fgetc($file);
00096   $header.=fgetc($file); $header.=fgetc($file);
00097   return $header;
00098 }
00099 
00100 function computeIndex($word)
00101 {
00102   if (strlen($word)<2) return -1;
00103   // high char of the index
00104   $hi = ord($word{0});
00105   if ($hi==0) return -1;
00106   // low char of the index
00107   $lo = ord($word{1});
00108   if ($lo==0) return -1;
00109   // return index
00110   return $hi*256+$lo;
00111 }
00112 
00113 function search($file,$word,&$statsList)
00114 {
00115   $index = computeIndex($word);
00116   if ($index!=-1) // found a valid index
00117   {
00118     fseek($file,$index*4+4); // 4 bytes per entry, skip header
00119     $index = readInt($file);
00120     if ($index) // found words matching first two characters
00121     {
00122       $start=sizeof($statsList);
00123       $count=$start;
00124       fseek($file,$index);
00125       $w = readString($file);
00126       while ($w)
00127       {
00128         $statIdx = readInt($file);
00129         if ($word==substr($w,0,strlen($word)))
00130         { // found word that matches (as substring)
00131           $statsList[$count++]=array(
00132               "word"=>$word,
00133               "match"=>$w,
00134               "index"=>$statIdx,
00135               "full"=>strlen($w)==strlen($word),
00136               "docs"=>array()
00137               );
00138         }
00139         $w = readString($file);
00140       }
00141       $totalHi=0;
00142       $totalFreqHi=0;
00143       $totalFreqLo=0;
00144       for ($count=$start;$count<sizeof($statsList);$count++)
00145       {
00146         $statInfo = &$statsList[$count];
00147         $multiplier = 1;
00148         // whole word matches have a double weight
00149         if ($statInfo["full"]) $multiplier=2;
00150         fseek($file,$statInfo["index"]); 
00151         $numDocs = readInt($file);
00152         $docInfo = array();
00153         // read docs info + occurrence frequency of the word
00154         for ($i=0;$i<$numDocs;$i++)
00155         {
00156           $idx=readInt($file); 
00157           $freq=readInt($file); 
00158           $docInfo[$i]=array("idx"  => $idx,
00159                              "freq" => $freq>>1,
00160                              "rank" => 0.0,
00161                              "hi"   => $freq&1
00162                             );
00163           if ($freq&1) // word occurs in high priority doc
00164           {
00165             $totalHi++;
00166             $totalFreqHi+=$freq*$multiplier;
00167           }
00168           else // word occurs in low priority doc
00169           {
00170             $totalFreqLo+=$freq*$multiplier;
00171           }
00172         }
00173         // read name and url info for the doc
00174         for ($i=0;$i<$numDocs;$i++)
00175         {
00176           fseek($file,$docInfo[$i]["idx"]);
00177           $docInfo[$i]["name"]=readString($file);
00178           $docInfo[$i]["url"]=readString($file);
00179         }
00180         $statInfo["docs"]=$docInfo;
00181       }
00182       $totalFreq=($totalHi+1)*$totalFreqLo + $totalFreqHi;
00183       for ($count=$start;$count<sizeof($statsList);$count++)
00184       {
00185         $statInfo = &$statsList[$count];
00186         $multiplier = 1;
00187         // whole word matches have a double weight
00188         if ($statInfo["full"]) $multiplier=2;
00189         for ($i=0;$i<sizeof($statInfo["docs"]);$i++)
00190         {
00191           $docInfo = &$statInfo["docs"];
00192           // compute frequency rank of the word in each doc
00193           $freq=$docInfo[$i]["freq"];
00194           if ($docInfo[$i]["hi"])
00195           {
00196             $statInfo["docs"][$i]["rank"]=
00197               (float)($freq*$multiplier+$totalFreqLo)/$totalFreq;
00198           }
00199           else
00200           {
00201             $statInfo["docs"][$i]["rank"]=
00202               (float)($freq*$multiplier)/$totalFreq;
00203           }
00204         }
00205       }
00206     }
00207   }
00208   return $statsList;
00209 }
00210 
00211 function combine_results($results,&$docs)
00212 {
00213   foreach ($results as $wordInfo)
00214   {
00215     $docsList = &$wordInfo["docs"];
00216     foreach ($docsList as $di)
00217     {
00218       $key=$di["url"];
00219       $rank=$di["rank"];
00220       if (in_array($key, array_keys($docs)))
00221       {
00222         $docs[$key]["rank"]+=$rank;
00223       }
00224       else
00225       {
00226         $docs[$key] = array("url"=>$key,
00227             "name"=>$di["name"],
00228             "rank"=>$rank
00229             );
00230       }
00231       $docs[$key]["words"][] = array(
00232                "word"=>$wordInfo["word"],
00233                "match"=>$wordInfo["match"],
00234                "freq"=>$di["freq"]
00235                );
00236     }
00237   }
00238   return $docs;
00239 }
00240 
00241 function filter_results($docs,&$requiredWords,&$forbiddenWords)
00242 {
00243   $filteredDocs=array();
00244   while (list ($key, $val) = each ($docs)) 
00245   {
00246     $words = &$docs[$key]["words"];
00247     $copy=1; // copy entry by default
00248     if (sizeof($requiredWords)>0)
00249     {
00250       foreach ($requiredWords as $reqWord)
00251       {
00252         $found=0;
00253         foreach ($words as $wordInfo)
00254         { 
00255           $found = $wordInfo["word"]==$reqWord;
00256           if ($found) break;
00257         }
00258         if (!$found) 
00259         {
00260           $copy=0; // document contains none of the required words
00261           break;
00262         }
00263       }
00264     }
00265     if (sizeof($forbiddenWords)>0)
00266     {
00267       foreach ($words as $wordInfo)
00268       {
00269         if (in_array($wordInfo["word"],$forbiddenWords))
00270         {
00271           $copy=0; // document contains a forbidden word
00272           break;
00273         }
00274       }
00275     }
00276     if ($copy) $filteredDocs[$key]=$docs[$key];
00277   }
00278   return $filteredDocs;
00279 }
00280 
00281 function compare_rank($a,$b)
00282 {
00283   if ($a["rank"] == $b["rank"]) 
00284   {
00285     return 0;
00286   }
00287   return ($a["rank"]>$b["rank"]) ? -1 : 1; 
00288 }
00289 
00290 function sort_results($docs,&$sorted)
00291 {
00292   $sorted = $docs;
00293   usort($sorted,"compare_rank");
00294   return $sorted;
00295 }
00296 
00297 function report_results(&$docs)
00298 {
00299   echo "<table cellspacing=\"2\">\n";
00300   echo "  <tr>\n";
00301   echo "    <td colspan=\"2\"><h2>".search_results()."</h2></td>\n";
00302   echo "  </tr>\n";
00303   $numDocs = sizeof($docs);
00304   if ($numDocs==0)
00305   {
00306     echo "  <tr>\n";
00307     echo "    <td colspan=\"2\">".matches_text(0)."</td>\n";
00308     echo "  </tr>\n";
00309   }
00310   else
00311   {
00312     echo "  <tr>\n";
00313     echo "    <td colspan=\"2\">".matches_text($numDocs);
00314     echo "\n";
00315     echo "    </td>\n";
00316     echo "  </tr>\n";
00317     $num=1;
00318     foreach ($docs as $doc)
00319     {
00320       echo "  <tr>\n";
00321       echo "    <td align=\"right\">$num.</td>";
00322       echo     "<td><a class=\"el\" href=\"".$doc["url"]."\">".$doc["name"]."</a></td>\n";
00323       echo "  <tr>\n";
00324       echo "    <td></td><td class=\"tiny\">".report_matches()." ";
00325       foreach ($doc["words"] as $wordInfo)
00326       {
00327         $word = $wordInfo["word"];
00328         $matchRight = substr($wordInfo["match"],strlen($word));
00329         echo "<b>$word</b>$matchRight(".$wordInfo["freq"].") ";
00330       }
00331       echo "    </td>\n";
00332       echo "  </tr>\n";
00333       $num++;
00334     }
00335   }
00336   echo "</table>\n";
00337 }
00338 
00339 function main()
00340 {
00341   if(strcmp('4.1.0', phpversion()) > 0) 
00342   {
00343     die("Error: PHP version 4.1.0 or above required!");
00344   }
00345   if (!($file=fopen("search.idx","rb"))) 
00346   {
00347     die("Error: Search index file could NOT be opened!");
00348   }
00349   if (readHeader($file)!="DOXS")
00350   {
00351     die("Error: Header of index file is invalid!");
00352   }
00353   $query="";
00354   if (array_key_exists("query", $_GET))
00355   {
00356     $query=$_GET["query"];
00357   }
00358   echo "<input class=\"search\" type=\"text\" name=\"query\" value=\"$query\" size=\"20\" accesskey=\"s\"/>\n";
00359   echo "</span>\n";
00360   echo "</form>\n";
00361   echo "</div>\n";
00362   $results = array();
00363   $requiredWords = array();
00364   $forbiddenWords = array();
00365   $foundWords = array();
00366   $word=strtok($query," ");
00367   while ($word) // for each word in the search query
00368   {
00369     if (($word{0}=='+')) { $word=substr($word,1); $requiredWords[]=$word; }
00370     if (($word{0}=='-')) { $word=substr($word,1); $forbiddenWords[]=$word; }
00371     if (!in_array($word,$foundWords))
00372     {
00373       $foundWords[]=$word;
00374       search($file,$word,$results);
00375     }
00376     $word=strtok(" ");
00377   }
00378   $docs = array();
00379   combine_results($results,$docs);
00380   // filter out documents with forbidden word or that do not contain
00381   // required words
00382   $filteredDocs = filter_results($docs,$requiredWords,$forbiddenWords);
00383   // sort the results based on rank
00384   $sorted = array();
00385   sort_results($filteredDocs,$sorted);
00386   // report results to the user
00387   report_results($sorted);
00388   fclose($file);
00389 }
00390 
00391 main();
00392 
00393 
00394 ?>
00395 </td></tr></tbody></table>
00396 
00397   <br>
00398   <table cellpadding="2" cellspacing="2" border="0" style="text-align: left; width: 100%; color: rgb(0, 0, 0);">
00399     <tbody>
00400       <tr>
00401         <td style="vertical-align: top;"><small>
00402             <b><a href="http://www.robertnz.net/nm_intro.htm">newmat11b</a><br></b>
00403           </small>
00404         </td>
00405         <td style="vertical-align: top; text-align: right; font-style: italic;">
00406           <small>
00407             Generated Tue Jan 4 15:05:35 2005 by <a href="http://www.doxygen.org/">Doxygen</a> 1.4.0
00408           </small>
00409           <script type="text/javascript" language="javascript">
00410             <!--
00411             s="na";c="na";j="na";f=""+escape(document.referrer)
00412             //-->
00413           </script>
00414           <script type="text/javascript" language="javascript1.2">
00415             <!--
00416             s=screen.width;v=navigator.appName
00417             if (v != "Netscape") {c=screen.colorDepth}
00418             else {c=screen.pixelDepth}
00419             j=navigator.javaEnabled()
00420             //-->
00421           </script>
00422           <script type="text/javascript" language="javascript">
00423             <!--
00424             function pr(n) {document.write(n,"\n");}
00425             NS2Ch=0
00426             if (navigator.appName == "Netscape" &&
00427             navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
00428             if (NS2Ch == 0) {
00429             r="size="+s+"&colors="+c+"&referer="+f+"&java="+j+"&stamp="+(new Date()).getTime()+""
00430             pr("<IMG BORDER=0 width=16 height=16 align=\"middle\" SRC=\"http://aibo2.boltz.cs.cmu.edu/head.gif?"+r+"\">")}
00431             //-->
00432           </script> 
00433           
00434           <noscript>
00435             <img src="http://aibo2.boltz.cs.cmu.edu/head.gif" border="0" width=16 height=16 align="middle">
00436           </noscript>
00437         </td>
00438       </tr>
00439     </tbody>
00440   </table>
00441 </body>
00442 </html>

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0