Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions phpdotnet/phd/IndexRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ protected function SQLiteIndex($context, $index, $id, $filename, $parent, $sdesc
];
}

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;
}
Expand Down
99 changes: 98 additions & 1 deletion phpdotnet/phd/Package/PHP/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,40 @@ protected function writeJsonIndex() {
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);
}

/**
* Processes the index to extract entries and descriptions. These are
* 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;
}

Expand All @@ -279,6 +302,80 @@ private function processJsonIndex(): array {
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.
*/
Expand Down
1 change: 1 addition & 0 deletions tests/render/render_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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