Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index reserved keywords for better user experience #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions gen-phpweb-sqlite-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function scan($dir, $lang)
'control-structures.', 'language.',
'about.', 'faq.', 'features.',
);

$count = 0;
echo "Lang: $lang\n";

Expand Down Expand Up @@ -115,7 +115,7 @@ function scan($dir, $lang)
if ($x !== false) {
$keyword = substr($keyword, 0, $x);
}

// Skip PHP 4 domxml (book.domxml). It uses function. syntax, unlike book.dom
if (0 === strpos($keyword, 'function.dom') && false === strpos($keyword, 'simplexml')) {
continue;
Expand Down Expand Up @@ -164,9 +164,33 @@ function scan($dir, $lang)
$dbh->exec("INSERT INTO fs (lang, prefix, keyword, name, prio) values ('$lang', '$prefix', '" . metaphone($keyword) . "', '$doc_rel', ".($prio+10).")");

}

if ($f === 'reserved.keywords.php' && $handle = fopen($file, 'r')) {
// Yes, this is fragile.
$stm = $dbh->prepare('INSERT INTO fs (lang, prefix, keyword, name, prio) VALUES (?, ?, ?, ?, ?)');
$path_base = dirname($doc_rel);
while ($stm && false !== ($line = fgets($handle))) {
if (strpos($line, '<a href=') === false) {
continue;
}

if (!preg_match('!<a href="([^"]+)" class="[^"]+">([^<]+)</a>!', $line, $matches)) {
continue;
}

$keyword = strtolower(rtrim($matches[2], '()'));
$href = $matches[1];

if ($x = strpos($href, '#')) {
$href = substr($href, 0, $x);
}

$stm->execute([$lang, $prefix ?? '', $keyword, $path_base . '/' . $href, $prio ?? 200]);
}
}
}
closedir($d);

echo "Added entries for $count files\n";
echo "\n";
}
Expand Down Expand Up @@ -195,4 +219,3 @@ function scan_langs($root)
}
closedir($d);
}