cvs: phpweb /include manual-lookup.inc
| From: | Wez Furlong | Date: | Tue, 13 May 2003 19:10:33 +0000 |
| Subject: | cvs: phpweb /include manual-lookup.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-17556@lists.php.net to get a copy of this message | ||
wez Tue May 13 15:10:33 2003 EDT
Modified files:
/phpweb/include manual-lookup.inc
Log:
Officially check-in support for a simple sqlite database to hold manual
information.
The effectively eliminates a whole bunch of stat() calls.
# It requires a database generated by a script on the server, which is
# not yet in CVS.
Index: phpweb/include/manual-lookup.inc
diff -u phpweb/include/manual-lookup.inc:1.15 phpweb/include/manual-lookup.inc:1.16
--- phpweb/include/manual-lookup.inc:1.15 Wed Jan 8 03:11:51 2003
+++ phpweb/include/manual-lookup.inc Tue May 13 15:10:33 2003
@@ -1,6 +1,6 @@
<?php // -*- C++ -*-
-// $Id: manual-lookup.inc,v 1.15 2003/01/08 08:11:51 goba Exp $
+// $Id: manual-lookup.inc,v 1.16 2003/05/13 19:10:33 wez Exp $
// Try to find some variations of keyword with $prefix in the $lang manual
function tryprefix($lang, $keyword, $prefix)
@@ -44,7 +44,7 @@
// Try to find a manual page in a specified
// language for the specified "keyword"
-function find_manual_page($lang, $keyword)
+function find_manual_page_slow($lang, $keyword)
{
// Possible prefixes to test
$sections = array(
@@ -69,6 +69,57 @@
// Nothing found
return "";
+}
+
+function find_manual_page($lang, $keyword)
+{
+ if (!function_exists("sqlite_open")) {
+ return find_manual_page_slow($lang, $keyword);
+ }
+
+ // In production, use sqlite_popen
+ $s = sqlite_popen("manual-lookup.sqlite");
+
+ /* generate keywords */
+
+ $keyword = str_replace('_', '-', $keyword);
+ $keyword = preg_replace("!\\(.*\\)!", "-", $keyword);
+
+ if (strlen($keyword) == 0) {
+ return "";
+ }
+
+ $keywords = array($keyword);
+
+ $keywords[] = str_replace(' ', '', $keyword);
+ $keywords[] = str_replace(' ', '-', $keyword);
+ $keywords[] = str_replace('-', '', $keyword);
+
+ $keywords = array_unique($keywords);
+ $words = "";
+ foreach ($keywords as $word) {
+ if (strlen($words)) {
+ $words .= ',';
+ }
+ $words .= "'" . sqlite_escape_string($word) . "'";
+ }
+
+ if ($lang != 'en') {
+ $langs = array(sqlite_escape_string($lang), 'en');
+ } else {
+ $langs = array('en');
+ }
+ foreach ($langs as $lang) {
+ $q = sqlite_query($s, "SELECT name from fs where lang='$lang' and keyword in
($words) order by prefix LIMIT 1");
+ if ($q) {
+ $r = sqlite_fetch_array($q, SQLITE_NUM);
+ if (is_array($r)) {
+ return $r[0];
+ }
+ }
+ }
+ return "";
+
}
?>