1
0
mirror of https://github.com/php/phd.git synced 2026-03-23 22:52:05 +01:00

Fix missing pages in search indexes (#212)

* Search indexes: Fix missing search entries

This handles duplicated ids - but requires changes on web-php to use new indexes
This commit is contained in:
AllenJB
2025-11-04 06:19:18 +00:00
committed by GitHub
parent deb7d81c49
commit 264c65b187
3 changed files with 109 additions and 1 deletions

View File

@@ -162,6 +162,16 @@ SQL;
];
}
public function getIndexesWithDuplicates(): array
{
$results = $this->db->query('SELECT docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next, chunk FROM ids');
$indexes = [];
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
$indexes[] = $row;
}
return $indexes;
}
private static function SQLiteFinal($context): mixed {
return $context;
}

View File

@@ -249,6 +249,18 @@ contributors($setup);
json_encode($descriptions)
);
$this->outputHandler->v("Index written", VERBOSE_FORMAT_RENDERING);
$entries = $this->processCombinedJsonIndex();
file_put_contents(
$this->getOutputDir() . "search-combined.json",
json_encode($entries)
);
$entries = 'var localSearchIndexes = '. json_encode($entries) .';';
file_put_contents(
$this->getOutputDir() . "search-combined.js",
$entries
);
$this->outputHandler->v("Combined Index written", VERBOSE_FORMAT_RENDERING);
}
/**
@@ -256,10 +268,21 @@ contributors($setup);
* used to generate the search index and the descriptions JSON files.
*/
private function processJsonIndex(): array {
$alwaysIncludeElements = [
'refentry',
'stream_wrapper',
'phpdoc:classref',
'phpdoc:exceptionref',
'phpdoc:varentry',
];
$entries = [];
$descriptions = [];
foreach($this->indexes as $id => $index) {
if (!$index["chunk"]) {
if (
(! $index['chunk'])
&& (! in_array($index['element'], $alwaysIncludeElements, true))
) {
continue;
}
@@ -281,6 +304,80 @@ contributors($setup);
return [$entries, $descriptions];
}
private function processCombinedJsonIndex(): array
{
$alwaysIncludeElements = [
'refentry',
'stream_wrapper',
'phpdoc:classref',
'phpdoc:exceptionref',
'phpdoc:varentry',
];
$entries = [];
$indexes = $this->indexRepository->getIndexesWithDuplicates();
foreach ($indexes as $index) {
if (
(! $index['chunk'])
&& (! in_array($index['element'], $alwaysIncludeElements, true))
) {
continue;
}
if ($index["sdesc"] === "" && $index["ldesc"] !== "") {
$index["sdesc"] = $index["ldesc"];
$bookOrSet = $this->findParentBookOrSet($index['parent_id']);
if ($bookOrSet) {
$index["ldesc"] = Format::getLongDescription(
$bookOrSet['docbook_id']
);
}
}
$nameParts = explode('::', $index['sdesc']);
$methodName = array_pop($nameParts);
if (str_contains('wrapper', $index['filename'])) {
print "Combined index: adding " . $index['filename'] . " :: " . $index['sdesc'] . "\n";
}
$type = 'General';
switch ($index['element']) {
case "phpdoc:varentry":
$type = "Variable";
break;
case "refentry":
$type = "Function";
break;
case "phpdoc:exceptionref":
$type = "Exception";
break;
case "phpdoc:classref":
$type = "Class";
break;
case "set":
case "book":
case "reference":
$type = "Extension";
break;
}
$entries[] = [
'id' => $index['filename'],
'name' => $index['sdesc'],
'description' => html_entity_decode($index['ldesc']),
'tag' => $index['element'],
'type' => $type,
'methodName' => $methodName,
];
}
return $entries;
}
/**
* Finds the closest parent book or set in the index hierarchy.
*/

View File

@@ -16,4 +16,5 @@ require_once __DIR__ . "/../../render.php";
%s[%d:%d:%d - Rendering Format ]%s Starting PHP-Web rendering
%s[%d:%d:%d - Rendering Format ]%s Writing search indexes..
%s[%d:%d:%d - Rendering Format ]%s Index written
%s[%d:%d:%d - Rendering Format ]%s Combined Index written
%s[%d:%d:%d - Rendering Format ]%s Finished rendering