svn: /web/php/trunk/include/ manual-lookup.inc
| From: | Philip Olson | Date: | Sat, 16 Jul 2011 16:59:20 +0000 |
| Subject: | svn: /web/php/trunk/include/ manual-lookup.inc | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-11661@lists.php.net to get a copy of this message | ||
philip Sat, 16 Jul 2011 16:59:20 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313283
Log:
Improved sqlite search. See the comments for @todo items, but removed slow LIKE and increased sqlite
hit frequency (e.g., php.net/function.strlen.php as per the 404 miss logs).
Changed paths:
U web/php/trunk/include/manual-lookup.inc
Modified: web/php/trunk/include/manual-lookup.inc
===================================================================
--- web/php/trunk/include/manual-lookup.inc 2011-07-16 14:11:11 UTC (rev 313282)
+++ web/php/trunk/include/manual-lookup.inc 2011-07-16 16:59:20 UTC (rev 313283)
@@ -126,11 +126,30 @@
// Check for all the languages
foreach ($langs as $lang) {
+ // @todo consider alternative schemas for this data
+ // @todo utilize phd to generate this data, instead of the current
systems/gen-phpweb-sqlite-db.php
+
+ /* Example data:
+ lang = en
+ name = /manual/en/function.str-replace.php
+ keyword = str-replace
+ prefix = function.
+ prio = 2
+
+ Therefore, the query below matches: str-replace, function.str-replace and
function.str-replace.php
+ This also applies to other sections like book.foo, language.foo, example.foo, etc.
+ Note: $keyword replaces _ with - above, so _ variants also work
+ */
if (strpos($keyword, ".") > 0) {
- $SQL = "SELECT name from fs WHERE name LIKE ? AND lang = ? ORDER BY prio LIMIT
1";
-
+ $SQL = "SELECT name from fs WHERE lang = ? AND (name = ? OR keyword = ?) ORDER BY
prio LIMIT 1";
+
+ $_keyword = $keyword;
+ if (pathinfo($keyword, PATHINFO_EXTENSION) !== 'php') {
+ $_keyword .= '.php';
+ }
+
$stm = $dbh->prepare($SQL);
- $stm->execute(array("%{$keyword}.php", $lang));
+ $stm->execute(array($lang, "/manual/{$lang}/{$_keyword}", $keyword));
// Some partially specified URL is used
} else {
@@ -163,6 +182,8 @@
// Match found
// But does the file really exist?
+ // @todo consider redirecting here, instead of including content within the 404
+ // @todo considering the file path is generated from the manual build, we can
probably remove this file_exists() check
if (file_exists($_SERVER["DOCUMENT_ROOT"] . $r[0])) {
return $r[0];
}
@@ -173,6 +194,9 @@
}
// No match found
+ // @todo refactor. find_manual_page_slow() performs many of the same searches already performed
above,
+ // but uses file_exists() instead of sqlite. In other words, if sqlite was used,
don't perform
+ // all of the slow and unnecessary checks.
return find_manual_page_slow($langs[0], $kw);
}