Skip to content

Commit

Permalink
Improve search index generation for PHP.net (#154)
Browse files Browse the repository at this point in the history
Improves the search indexes generated by the PHP-Web format by:
- Adding short descriptions to entries that lack them
- Skipping non-chunk entries (page elements)
  • Loading branch information
lhsazevedo authored Oct 6, 2024
1 parent 5bfb7f6 commit 673b2da
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions phpdotnet/phd/Package/PHP/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ protected function writeJsonIndex() {
$ids = array();
$desc = array();
foreach($this->indexes as $id => $index) {
if (!$index["chunk"]) {
continue;
}

if ($index["sdesc"] === "" && $index["ldesc"] !== "") {
$index["sdesc"] = $index["ldesc"];

$parentId = $index['parent_id'];
// isset() to guard against undefined array keys, either for root
// elements (no parent) or in case the index structure is broken.
while (isset($this->indexes[$parentId])) {
$parent = $this->indexes[$parentId];
if ($parent['element'] === 'book') {
$index["ldesc"] = Format::getLongDescription($parent['docbook_id']);
break;
}
$parentId = $parent['parent_id'];
}
}

$ids[] = array($index["sdesc"], $index["filename"], $index["element"]);
$desc[$id] = $index["ldesc"];
}
Expand Down

0 comments on commit 673b2da

Please sign in to comment.