2 $query = $HTTP_GET_VARS[ "query" ];
3 $scope = $HTTP_GET_VARS[ "scope" ];
4 // We handle only the first argument so far
5 $query = $_GET['query'];
6 $query = ltrim ($query);
8 echo "<h1 align='center'>Search the documentation on XMLSoft.org</h1>";
12 $scope = ltrim ($scope);
17 <p> The search service indexes the libxml2 and libxslt APIs and documentation as well as the xml@gnome.org and xslt@gnome.org mailing-list archives. To use it simply provide a set of keywords:
19 <form action="<?php echo "$PHP_SELF", "?query=", rawurlencode($query) ?>"
20 enctype="application/x-www-form-urlencoded" method="GET">
21 <input name="query" type="TEXT" size="50" value="<?php echo $query?>">
23 <option value="any">Search All</option>
24 <option value="XML" <?php if ($scope == 'XML') print "selected"?>>XML resources</option>
25 <option value="XSLT" <?php if ($scope == 'XSLT') print "selected"?>>XSLT resources</option>
26 <option value="API" <?php if ($scope == 'API') print "selected"?>>Only the APIs</option>
27 <option value="XMLAPI" <?php if ($scope == 'XMLAPI') print "selected"?>>Only the XML API</option>
28 <option value="XSLTAPI" <?php if ($scope == 'XSLTAPI') print "selected"?>>Only the XSLT API</option>
29 <option value="DOCS" <?php if ($scope == 'DOCS') print "selected"?>>Only the Documentation</option>
30 <option value="XMLDOC" <?php if ($scope == 'XMLDOC') print "selected"?>>Only the XML Documentation</option>
31 <option value="XSLTDOC" <?php if ($scope == 'XSLTDOC') print "selected"?>>Only the XSLT Documentation</option>
32 <option value="LISTS" <?php if ($scope == 'LISTS') print "selected"?>>Only the lists archives</option>
33 <option value="XMLLIST" <?php if ($scope == 'XMLLIST') print "selected"?>>Only the XML list archive</option>
34 <option value="XSLTLIST" <?php if ($scope == 'XSLTLIST') print "selected"?>>Only the XSLT list archive</option>
36 <input name=submit type=submit value="Search ...">
39 function logQueryWord($word) {
40 $result = mysql_query ("SELECT ID,Count FROM Queries WHERE Value='$word'");
42 $i = mysql_num_rows($result);
44 mysql_free_result($result);
45 mysql_query ("INSERT INTO Queries (Value,Count) VALUES ('$word',1)");
47 $id = mysql_result($result, 0, 0);
48 $count = mysql_result($result, 0, 1);
50 mysql_query ("UPDATE Queries SET Count=$count WHERE ID=$id");
53 mysql_query ("INSERT INTO Queries (Value,Count) VALUES ('$word',1)");
56 function queryWord($word) {
60 $result = mysql_query ("SELECT words.relevance, symbols.name, symbols.type, symbols.module, symbols.descr FROM words, symbols WHERE LCASE(words.name) LIKE LCASE('$word') and words.symbol = symbols.name ORDER BY words.relevance DESC LIMIT 75");
62 $j = mysql_num_rows($result);
64 mysql_free_result($result);
68 return array($result, $j);
70 function queryHTMLWord($word) {
74 $result = mysql_query ("SELECT relevance, name, id, resource, section FROM wordsHTML WHERE LCASE(name) LIKE LCASE('$word') ORDER BY relevance DESC LIMIT 75");
76 $j = mysql_num_rows($result);
78 mysql_free_result($result);
82 return array($result, $j);
84 function queryArchiveWord($word) {
88 $result = mysql_query ("SELECT wordsArchive.relevance, wordsArchive.name, 'xml-list', archives.resource, archives.title FROM wordsArchive, archives WHERE LCASE(wordsArchive.name) LIKE LCASE('$word') and wordsArchive.ID = archives.ID ORDER BY relevance DESC LIMIT 75");
90 $j = mysql_num_rows($result);
92 mysql_free_result($result);
96 return array($result, $j);
98 function XSLTqueryWord($word) {
102 $result = mysql_query ("SELECT XSLTwords.relevance, XSLTsymbols.name, XSLTsymbols.type, XSLTsymbols.module, XSLTsymbols.descr FROM XSLTwords, XSLTsymbols WHERE LCASE(XSLTwords.name) LIKE LCASE('$word') and XSLTwords.symbol = XSLTsymbols.name ORDER BY XSLTwords.relevance DESC LIMIT 75");
104 $j = mysql_num_rows($result);
106 mysql_free_result($result);
110 return array($result, $j);
112 function XSLTqueryHTMLWord($word) {
116 $result = mysql_query ("SELECT relevance, name, id, resource, section FROM XSLTwordsHTML WHERE LCASE(name) LIKE LCASE('$word') ORDER BY relevance DESC LIMIT 75");
118 $j = mysql_num_rows($result);
120 mysql_free_result($result);
124 return array($result, $j);
126 function XSLTqueryArchiveWord($word) {
130 $result = mysql_query ("SELECT XSLTwordsArchive.relevance, XSLTwordsArchive.name, 'xslt-list', archives.resource, archives.title FROM XSLTwordsArchive, archives WHERE LCASE(XSLTwordsArchive.name) LIKE LCASE('$word') and XSLTwordsArchive.ID = archives.ID ORDER BY relevance DESC LIMIT 75");
132 $j = mysql_num_rows($result);
134 mysql_free_result($result);
138 return array($result, $j);
140 function resSort ($a, $b) {
141 list($ra,$ta,$ma,$na,$da) = $a;
142 list($rb,$tb,$mb,$nb,$db) = $b;
143 if ($ra == $rb) return 0;
144 return ($ra > $rb) ? -1 : 1;
146 if (($query) && (strlen($query) <= 50)) {
147 $link = mysql_connect ("localhost", "nobody");
149 echo "<p> Could not connect to the database: ", mysql_error();
151 mysql_select_db("xmlsoft", $link);
152 $list = explode (" ", $query);
155 for ($number = 0;$number < count($list);$number++) {
157 $word = $list[$number];
158 if (($scope == 'any') || ($scope == 'XML') ||
159 ($scope == 'API') || ($scope == 'XMLAPI')) {
160 list($result, $j) = queryWord($word);
162 for ($i = 0; $i < $j; $i++) {
163 $relevance = mysql_result($result, $i, 0);
164 $name = mysql_result($result, $i, 1);
165 $type = mysql_result($result, $i, 2);
166 $module = mysql_result($result, $i, 3);
167 $desc = mysql_result($result, $i, 4);
168 if (array_key_exists($name, $results)) {
169 list($r,$t,$m,$d,$w,$u) = $results[$name];
170 $results[$name] = array(($r + $relevance) * 2,
173 $id = strtoupper($name);
174 // $m = strtolower($module);
176 $url = "../html/libxml-$m.html#$id";
177 $results[$name] = array($relevance,$type,
178 $module, $desc, $name, $url);
181 mysql_free_result($result);
184 if (($scope == 'any') || ($scope == 'XSLT') ||
185 ($scope == 'API') || ($scope == 'XSLTAPI')) {
186 list($result, $j) = XSLTqueryWord($word);
188 for ($i = 0; $i < $j; $i++) {
189 $relevance = mysql_result($result, $i, 0);
190 $name = mysql_result($result, $i, 1);
191 $type = mysql_result($result, $i, 2);
192 $module = mysql_result($result, $i, 3);
193 $desc = mysql_result($result, $i, 4);
194 if (array_key_exists($name, $results)) {
195 list($r,$t,$m,$d,$w,$u) = $results[$name];
196 $results[$name] = array(($r + $relevance) * 2,
199 $id = strtoupper($name);
200 // $m = strtolower($module);
202 $url = "html/libxslt-$m.html#$id";
203 $results[$name] = array($relevance,$type,
204 $module, $desc, $name, $url);
207 mysql_free_result($result);
210 if (($scope == 'any') || ($scope == 'XML') ||
211 ($scope == 'DOCS') || ($scope == 'XMLDOC')) {
212 list($result, $k) = queryHTMLWord($word);
214 for ($i = 0; $i < $k; $i++) {
215 $relevance = mysql_result($result, $i, 0);
216 $name = mysql_result($result, $i, 1);
217 $id = mysql_result($result, $i, 2);
218 $module = mysql_result($result, $i, 3);
219 $desc = mysql_result($result, $i, 4);
222 $url = $url + "#$id";
224 $results["$name _html_ $number _ $i"] =
225 array($relevance, "XML docs",
226 $module, $desc, $name, $url);
228 mysql_free_result($result);
231 if (($scope == 'any') || ($scope == 'XSLT') ||
232 ($scope == 'DOCS') || ($scope == 'XSLTDOC')) {
233 list($result, $k) = XSLTqueryHTMLWord($word);
235 for ($i = 0; $i < $k; $i++) {
236 $relevance = mysql_result($result, $i, 0);
237 $name = mysql_result($result, $i, 1);
238 $id = mysql_result($result, $i, 2);
239 $module = mysql_result($result, $i, 3);
240 $desc = mysql_result($result, $i, 4);
243 $url = $url + "#$id";
245 $results["$name xslthtml $number _ $i "] =
246 array($relevance, "XSLT docs",
247 $module, $desc, $name, $url);
249 mysql_free_result($result);
252 if (($scope == 'any') || ($scope == 'XML') ||
253 ($scope == 'LISTS') || ($scope == 'XMLLIST')) {
254 list($result, $j) = queryArchiveWord($word);
256 for ($i = 0; $i < $j; $i++) {
257 $relevance = mysql_result($result, $i, 0);
258 $name = mysql_result($result, $i, 1);
259 $type = mysql_result($result, $i, 2);
260 $url = mysql_result($result, $i, 3);
261 $desc = mysql_result($result, $i, 4);
262 if (array_key_exists($url, $results)) {
263 list($r,$t,$m,$d,$w,$u) = $results[$url];
264 $results[$name] = array(($r + $relevance) * 2,
267 $id = strtoupper($name);
268 // $m = strtolower($module);
271 "http://mail.gnome.org/archives/xml/", "", $url);
272 $results[$url] = array($relevance,$type,
273 $u, $desc, $name, $url);
276 mysql_free_result($result);
279 if (($scope == 'any') || ($scope == 'XSLT') ||
280 ($scope == 'LISTS') || ($scope == 'XSLTLIST')) {
281 list($result, $j) = XSLTqueryArchiveWord($word);
283 for ($i = 0; $i < $j; $i++) {
284 $relevance = mysql_result($result, $i, 0);
285 $name = mysql_result($result, $i, 1);
286 $type = mysql_result($result, $i, 2);
287 $url = mysql_result($result, $i, 3);
288 $desc = mysql_result($result, $i, 4);
289 if (array_key_exists($url, $results)) {
290 list($r,$t,$m,$d,$w,$u) = $results[$url];
291 $results[$name] = array(($r + $relevance) * 2,
294 $id = strtoupper($name);
295 // $m = strtolower($module);
298 "http://mail.gnome.org/archives/xslt/", "", $url);
299 $results[$url] = array($relevance,$type,
300 $u, $desc, $name, $url);
303 mysql_free_result($result);
306 if (($j <= 0) && ($k <= 0)) {
307 echo "<p> No result found for $word\n";
311 $nb = count($results);
312 echo "<h3 align='center'>Found $nb results for query $query</h3>\n";
313 usort($results, "resSort");
316 printf("<table><tbody>\n");
317 printf("<tr><td>Quality</td><td>Symbol</td><td>Type</td><td>module</td><td>Description</td></tr>\n");
319 while (list ($name, $val) = each ($results)) {
320 list($r,$t,$m,$d,$s,$u) = $val;
321 $m = str_replace("<", "<", $m);
322 $s = str_replace("<", "<", $s);
323 $d = str_replace("<", "<", $d);
324 echo "<tr><td>$r</td><td><a href='$u'>$s</a></td><td>$t</td><td>$m</td><td>$d</td></tr>";
329 printf("</tbody></table>\n");