1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3
<title>Recherche</title>
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
5
<link href="tabs.css" rel="stylesheet" type="text/css">
7
<!-- Généré par Doxygen 1.5.3 -->
10
<li><a href="index.html"><span>Page principale</span></a></li>
11
<li><a href="annotated.html"><span>Structures de données</span></a></li>
12
<li><a href="files.html"><span>Fichiers</span></a></li>
14
<form action="search.php" method="get">
15
<table cellspacing="0" cellpadding="0" border="0">
17
<td><label> Rechercher </label></td>
21
function search_results()
23
return "Résultats de la recherche";
26
function matches_text($num)
30
return "Désolé aucun document ne correspond à votre requête.";
34
return "Trouvé <b>1</b> document correspondant à votre requête.";
38
return "Trouvé <b>$num</b> documents correspondant à votre requête. Classé par ordre de pertinence décroissant.";
42
function report_matches()
44
return "Correspondances : ";
46
function end_form($value)
48
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";
51
function readInt($file)
53
$b1 = ord(fgetc($file)); $b2 = ord(fgetc($file));
54
$b3 = ord(fgetc($file)); $b4 = ord(fgetc($file));
55
return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
58
function readString($file)
61
while (ord($c=fgetc($file))) $result.=$c;
65
function readHeader($file)
67
$header =fgetc($file); $header.=fgetc($file);
68
$header.=fgetc($file); $header.=fgetc($file);
72
function computeIndex($word)
74
// Fast string hashing
75
//$lword = strtolower($word);
76
//$l = strlen($lword);
77
//for ($i=0;$i<$l;$i++)
79
// $c = ord($lword{$i});
80
// $v = (($v & 0xfc00) ^ ($v << 6) ^ $c) & 0xffff;
84
// Simple hashing that allows for substring search
85
if (strlen($word)<2) return -1;
86
// high char of the index
88
if ($hi==0) return -1;
89
// low char of the index
91
if ($lo==0) return -1;
96
function search($file,$word,&$statsList)
98
$index = computeIndex($word);
99
if ($index!=-1) // found a valid index
101
fseek($file,$index*4+4); // 4 bytes per entry, skip header
102
$index = readInt($file);
103
if ($index) // found words matching the hash key
105
$start=sizeof($statsList);
108
$w = readString($file);
111
$statIdx = readInt($file);
112
if ($word==substr($w,0,strlen($word)))
113
{ // found word that matches (as substring)
114
$statsList[$count++]=array(
118
"full"=>strlen($w)==strlen($word),
122
$w = readString($file);
127
for ($count=$start;$count<sizeof($statsList);$count++)
129
$statInfo = &$statsList[$count];
131
// whole word matches have a double weight
132
if ($statInfo["full"]) $multiplier=2;
133
fseek($file,$statInfo["index"]);
134
$numDocs = readInt($file);
136
// read docs info + occurrence frequency of the word
137
for ($i=0;$i<$numDocs;$i++)
140
$freq=readInt($file);
141
$docInfo[$i]=array("idx" => $idx,
146
if ($freq&1) // word occurs in high priority doc
149
$totalFreqHi+=$freq*$multiplier;
151
else // word occurs in low priority doc
153
$totalFreqLo+=$freq*$multiplier;
156
// read name and url info for the doc
157
for ($i=0;$i<$numDocs;$i++)
159
fseek($file,$docInfo[$i]["idx"]);
160
$docInfo[$i]["name"]=readString($file);
161
$docInfo[$i]["url"]=readString($file);
163
$statInfo["docs"]=$docInfo;
165
$totalFreq=($totalHi+1)*$totalFreqLo + $totalFreqHi;
166
for ($count=$start;$count<sizeof($statsList);$count++)
168
$statInfo = &$statsList[$count];
170
// whole word matches have a double weight
171
if ($statInfo["full"]) $multiplier=2;
172
for ($i=0;$i<sizeof($statInfo["docs"]);$i++)
174
$docInfo = &$statInfo["docs"];
175
// compute frequency rank of the word in each doc
176
$freq=$docInfo[$i]["freq"];
177
if ($docInfo[$i]["hi"])
179
$statInfo["docs"][$i]["rank"]=
180
(float)($freq*$multiplier+$totalFreqLo)/$totalFreq;
184
$statInfo["docs"][$i]["rank"]=
185
(float)($freq*$multiplier)/$totalFreq;
194
function combine_results($results,&$docs)
196
foreach ($results as $wordInfo)
198
$docsList = &$wordInfo["docs"];
199
foreach ($docsList as $di)
203
if (in_array($key, array_keys($docs)))
205
$docs[$key]["rank"]+=$rank;
209
$docs[$key] = array("url"=>$key,
214
$docs[$key]["words"][] = array(
215
"word"=>$wordInfo["word"],
216
"match"=>$wordInfo["match"],
224
function filter_results($docs,&$requiredWords,&$forbiddenWords)
226
$filteredDocs=array();
227
while (list ($key, $val) = each ($docs))
229
$words = &$docs[$key]["words"];
230
$copy=1; // copy entry by default
231
if (sizeof($requiredWords)>0)
233
foreach ($requiredWords as $reqWord)
236
foreach ($words as $wordInfo)
238
$found = $wordInfo["word"]==$reqWord;
243
$copy=0; // document contains none of the required words
248
if (sizeof($forbiddenWords)>0)
250
foreach ($words as $wordInfo)
252
if (in_array($wordInfo["word"],$forbiddenWords))
254
$copy=0; // document contains a forbidden word
259
if ($copy) $filteredDocs[$key]=$docs[$key];
261
return $filteredDocs;
264
function compare_rank($a,$b)
266
if ($a["rank"] == $b["rank"])
270
return ($a["rank"]>$b["rank"]) ? -1 : 1;
273
function sort_results($docs,&$sorted)
276
usort($sorted,"compare_rank");
280
function report_results(&$docs)
282
echo "<table cellspacing=\"2\">\n";
284
echo " <td colspan=\"2\"><h2>".search_results()."</h2></td>\n";
286
$numDocs = sizeof($docs);
290
echo " <td colspan=\"2\">".matches_text(0)."</td>\n";
296
echo " <td colspan=\"2\">".matches_text($numDocs);
301
foreach ($docs as $doc)
304
echo " <td align=\"right\">$num.</td>";
305
echo "<td><a class=\"el\" href=\"".$doc["url"]."\">".$doc["name"]."</a></td>\n";
307
echo " <td></td><td class=\"tiny\">".report_matches()." ";
308
foreach ($doc["words"] as $wordInfo)
310
$word = $wordInfo["word"];
311
$matchRight = substr($wordInfo["match"],strlen($word));
312
echo "<b>$word</b>$matchRight(".$wordInfo["freq"].") ";
324
if(strcmp('4.1.0', phpversion()) > 0)
326
die("Error: PHP version 4.1.0 or above required!");
328
if (!($file=fopen("search.idx","rb")))
330
die("Error: Search index file could NOT be opened!");
332
if (readHeader($file)!="DOXS")
334
die("Error: Header of index file is invalid!");
337
if (array_key_exists("query", $_GET))
339
$query=$_GET["query"];
342
echo " \n<div class=\"searchresults\">\n";
344
$requiredWords = array();
345
$forbiddenWords = array();
346
$foundWords = array();
347
$word=strtok($query," ");
348
while ($word) // for each word in the search query
350
if (($word{0}=='+')) { $word=substr($word,1); $requiredWords[]=$word; }
351
if (($word{0}=='-')) { $word=substr($word,1); $forbiddenWords[]=$word; }
352
if (!in_array($word,$foundWords))
355
search($file,strtolower($word),$results);
360
combine_results($results,$docs);
361
// filter out documents with forbidden word or that do not contain
363
$filteredDocs = filter_results($docs,$requiredWords,$forbiddenWords);
364
// sort the results based on rank
366
sort_results($filteredDocs,$sorted);
367
// report results to the user
368
report_results($sorted);
377
<hr size="1"><address style="text-align: right;"><small>Généré le Wed Apr 16 03:27:16 2008 pour Cairo-Dock par
378
<a href="http://www.doxygen.org/index.html">
379
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>