diff --git a/phpdotnet/phd/IndexRepository.php b/phpdotnet/phd/IndexRepository.php index cd947699..0ecf5dd1 100644 --- a/phpdotnet/phd/IndexRepository.php +++ b/phpdotnet/phd/IndexRepository.php @@ -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; } diff --git a/phpdotnet/phd/Package/PHP/Web.php b/phpdotnet/phd/Package/PHP/Web.php index 31068bbb..59b93c64 100644 --- a/phpdotnet/phd/Package/PHP/Web.php +++ b/phpdotnet/phd/Package/PHP/Web.php @@ -247,6 +247,18 @@ 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); } /** @@ -254,10 +266,21 @@ protected function writeJsonIndex() { * 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; } @@ -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. */ diff --git a/tests/render/render_001.phpt b/tests/render/render_001.phpt index 2056232d..813bfa9d 100644 --- a/tests/render/render_001.phpt +++ b/tests/render/render_001.phpt @@ -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