1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>XED2: XED2 User Guide - Thu May 15 03:15:09 2008 </title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 <link href="tabs.css" rel="stylesheet" type="text/css">
7 <!-- Generated by Doxygen 1.4.6 -->
10 <li><a href="main.html"><span>Main Page</span></a></li>
11 <li><a href="modules.html"><span>Modules</span></a></li>
12 <li><a href="classes.html"><span>Data Structures</span></a></li>
13 <li><a href="files.html"><span>Files</span></a></li>
15 <form action="search.php" method="get">
16 <table cellspacing="0" cellpadding="0" border="0">
18 <td><label> <u>S</u>earch for </label></td>
22 function search_results()
24 return "Search Results";
27 function matches_text($num)
31 return "Sorry, no documents matching your query.";
35 return "Found <b>1</b> document matching your query.";
39 return "Found <b>$num</b> documents matching your query. Showing best matches first.";
43 function report_matches()
47 function end_form($value)
49 echo " <td><input type=\"text\" name=\"query\" value=\"$value\" size=\"20\" accesskey=\"s\"/></td>\n </tr>\n </table>\n </form>\n </li>\n </ul>\n</div>\n";
52 function readInt($file)
54 $b1 = ord(fgetc($file)); $b2 = ord(fgetc($file));
55 $b3 = ord(fgetc($file)); $b4 = ord(fgetc($file));
56 return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
59 function readString($file)
62 while (ord($c=fgetc($file))) $result.=$c;
66 function readHeader($file)
68 $header =fgetc($file); $header.=fgetc($file);
69 $header.=fgetc($file); $header.=fgetc($file);
73 function computeIndex($word)
75 // Fast string hashing
76 //$lword = strtolower($word);
77 //$l = strlen($lword);
78 //for ($i=0;$i<$l;$i++)
80 // $c = ord($lword{$i});
81 // $v = (($v & 0xfc00) ^ ($v << 6) ^ $c) & 0xffff;
85 // Simple hashing that allows for substring search
86 if (strlen($word)<2) return -1;
87 // high char of the index
89 if ($hi==0) return -1;
90 // low char of the index
92 if ($lo==0) return -1;
97 function search($file,$word,&$statsList)
99 $index = computeIndex($word);
100 if ($index!=-1) // found a valid index
102 fseek($file,$index*4+4); // 4 bytes per entry, skip header
103 $index = readInt($file);
104 if ($index) // found words matching the hash key
106 $start=sizeof($statsList);
109 $w = readString($file);
112 $statIdx = readInt($file);
113 if ($word==substr($w,0,strlen($word)))
114 { // found word that matches (as substring)
115 $statsList[$count++]=array(
119 "full"=>strlen($w)==strlen($word),
123 $w = readString($file);
128 for ($count=$start;$count<sizeof($statsList);$count++)
130 $statInfo = &$statsList[$count];
132 // whole word matches have a double weight
133 if ($statInfo["full"]) $multiplier=2;
134 fseek($file,$statInfo["index"]);
135 $numDocs = readInt($file);
137 // read docs info + occurrence frequency of the word
138 for ($i=0;$i<$numDocs;$i++)
141 $freq=readInt($file);
142 $docInfo[$i]=array("idx" => $idx,
147 if ($freq&1) // word occurs in high priority doc
150 $totalFreqHi+=$freq*$multiplier;
152 else // word occurs in low priority doc
154 $totalFreqLo+=$freq*$multiplier;
157 // read name and url info for the doc
158 for ($i=0;$i<$numDocs;$i++)
160 fseek($file,$docInfo[$i]["idx"]);
161 $docInfo[$i]["name"]=readString($file);
162 $docInfo[$i]["url"]=readString($file);
164 $statInfo["docs"]=$docInfo;
166 $totalFreq=($totalHi+1)*$totalFreqLo + $totalFreqHi;
167 for ($count=$start;$count<sizeof($statsList);$count++)
169 $statInfo = &$statsList[$count];
171 // whole word matches have a double weight
172 if ($statInfo["full"]) $multiplier=2;
173 for ($i=0;$i<sizeof($statInfo["docs"]);$i++)
175 $docInfo = &$statInfo["docs"];
176 // compute frequency rank of the word in each doc
177 $freq=$docInfo[$i]["freq"];
178 if ($docInfo[$i]["hi"])
180 $statInfo["docs"][$i]["rank"]=
181 (float)($freq*$multiplier+$totalFreqLo)/$totalFreq;
185 $statInfo["docs"][$i]["rank"]=
186 (float)($freq*$multiplier)/$totalFreq;
195 function combine_results($results,&$docs)
197 foreach ($results as $wordInfo)
199 $docsList = &$wordInfo["docs"];
200 foreach ($docsList as $di)
204 if (in_array($key, array_keys($docs)))
206 $docs[$key]["rank"]+=$rank;
210 $docs[$key] = array("url"=>$key,
215 $docs[$key]["words"][] = array(
216 "word"=>$wordInfo["word"],
217 "match"=>$wordInfo["match"],
225 function filter_results($docs,&$requiredWords,&$forbiddenWords)
227 $filteredDocs=array();
228 while (list ($key, $val) = each ($docs))
230 $words = &$docs[$key]["words"];
231 $copy=1; // copy entry by default
232 if (sizeof($requiredWords)>0)
234 foreach ($requiredWords as $reqWord)
237 foreach ($words as $wordInfo)
239 $found = $wordInfo["word"]==$reqWord;
244 $copy=0; // document contains none of the required words
249 if (sizeof($forbiddenWords)>0)
251 foreach ($words as $wordInfo)
253 if (in_array($wordInfo["word"],$forbiddenWords))
255 $copy=0; // document contains a forbidden word
260 if ($copy) $filteredDocs[$key]=$docs[$key];
262 return $filteredDocs;
265 function compare_rank($a,$b)
267 if ($a["rank"] == $b["rank"])
271 return ($a["rank"]>$b["rank"]) ? -1 : 1;
274 function sort_results($docs,&$sorted)
277 usort($sorted,"compare_rank");
281 function report_results(&$docs)
283 echo "<table cellspacing=\"2\">\n";
285 echo " <td colspan=\"2\"><h2>".search_results()."</h2></td>\n";
287 $numDocs = sizeof($docs);
291 echo " <td colspan=\"2\">".matches_text(0)."</td>\n";
297 echo " <td colspan=\"2\">".matches_text($numDocs);
302 foreach ($docs as $doc)
305 echo " <td align=\"right\">$num.</td>";
306 echo "<td><a class=\"el\" href=\"".$doc["url"]."\">".$doc["name"]."</a></td>\n";
308 echo " <td></td><td class=\"tiny\">".report_matches()." ";
309 foreach ($doc["words"] as $wordInfo)
311 $word = $wordInfo["word"];
312 $matchRight = substr($wordInfo["match"],strlen($word));
313 echo "<b>$word</b>$matchRight(".$wordInfo["freq"].") ";
325 if(strcmp('4.1.0', phpversion()) > 0)
327 die("Error: PHP version 4.1.0 or above required!");
329 if (!($file=fopen("search.idx","rb")))
331 die("Error: Search index file could NOT be opened!");
333 if (readHeader($file)!="DOXS")
335 die("Error: Header of index file is invalid!");
338 if (array_key_exists("query", $_GET))
340 $query=$_GET["query"];
343 echo " \n<div class=\"searchresults\">\n";
345 $requiredWords = array();
346 $forbiddenWords = array();
347 $foundWords = array();
348 $word=strtok($query," ");
349 while ($word) // for each word in the search query
351 if (($word{0}=='+')) { $word=substr($word,1); $requiredWords[]=$word; }
352 if (($word{0}=='-')) { $word=substr($word,1); $forbiddenWords[]=$word; }
353 if (!in_array($word,$foundWords))
356 search($file,strtolower($word),$results);
361 combine_results($results,$docs);
362 // filter out documents with forbidden word or that do not contain
364 $filteredDocs = filter_results($docs,$requiredWords,$forbiddenWords);
365 // sort the results based on rank
367 sort_results($filteredDocs,$sorted);
368 // report results to the user
369 report_results($sorted);
378 <hr size="1"><address style="align: right;"><small>Generated on Thu May 15 03:15:09 2008 for XED2 by
379 <a href="http://www.doxygen.org/index.html">
380 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>