From 94f188251e1f778919785b8cb6be4a43f3bd2758 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Mon, 3 Nov 2025 14:18:46 +0000 Subject: [PATCH 1/5] Search indexes: Fix some missing search entries (some still missing due to duplicated ids) --- phpdotnet/phd/Package/PHP/Web.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/phpdotnet/phd/Package/PHP/Web.php b/phpdotnet/phd/Package/PHP/Web.php index 31068bbb..0ae35eab 100644 --- a/phpdotnet/phd/Package/PHP/Web.php +++ b/phpdotnet/phd/Package/PHP/Web.php @@ -254,10 +254,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 ( + (! in_array($index['element'], $alwaysIncludeElements, true)) + && (! $index['chunk']) + ) { continue; } From 01de848317249c369483a07b93d8674f36b4dbde Mon Sep 17 00:00:00 2001 From: AllenJB Date: Mon, 3 Nov 2025 15:24:52 +0000 Subject: [PATCH 2/5] Search indexes: Fix missing search entries (with duplicated ids - requires changes on web-php to use new indexes) --- phpdotnet/phd/IndexRepository.php | 11 ++++ phpdotnet/phd/Package/PHP/Web.php | 86 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/phpdotnet/phd/IndexRepository.php b/phpdotnet/phd/IndexRepository.php index cd947699..6e6d81ce 100644 --- a/phpdotnet/phd/IndexRepository.php +++ b/phpdotnet/phd/IndexRepository.php @@ -4,6 +4,7 @@ class IndexRepository { private array $indexes = []; + private array $indexesDuped = []; private array $children = []; private array $refs = []; private array $vars = []; @@ -162,6 +163,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 0ae35eab..e456bb76 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); } /** @@ -290,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 ( + (! in_array($index['element'], $alwaysIncludeElements, true)) + && (! $index['chunk']) + ) { + 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. */ From f43716e8536ab747816087790a22fa7e7d8879a1 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Mon, 3 Nov 2025 15:26:57 +0000 Subject: [PATCH 3/5] Search indexes: Fix missing search entries (update tests) --- tests/render/render_001.phpt | 1 + 1 file changed, 1 insertion(+) 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 From e5c35f8fe044693cec1c03e013f2de14246ad792 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Mon, 3 Nov 2025 15:49:24 +0000 Subject: [PATCH 4/5] Search indexes: Fix missing search entries (tidy-up) --- phpdotnet/phd/IndexRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpdotnet/phd/IndexRepository.php b/phpdotnet/phd/IndexRepository.php index 6e6d81ce..0ecf5dd1 100644 --- a/phpdotnet/phd/IndexRepository.php +++ b/phpdotnet/phd/IndexRepository.php @@ -4,7 +4,6 @@ class IndexRepository { private array $indexes = []; - private array $indexesDuped = []; private array $children = []; private array $refs = []; private array $vars = []; From 72c544ea815678348314b93d8cd1bb55c2fa0d94 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Mon, 3 Nov 2025 16:41:13 +0000 Subject: [PATCH 5/5] Search indexes: Fix missing search entries (review amends - if check order) --- phpdotnet/phd/Package/PHP/Web.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpdotnet/phd/Package/PHP/Web.php b/phpdotnet/phd/Package/PHP/Web.php index e456bb76..59b93c64 100644 --- a/phpdotnet/phd/Package/PHP/Web.php +++ b/phpdotnet/phd/Package/PHP/Web.php @@ -278,8 +278,8 @@ private function processJsonIndex(): array { $descriptions = []; foreach($this->indexes as $id => $index) { if ( - (! in_array($index['element'], $alwaysIncludeElements, true)) - && (! $index['chunk']) + (! $index['chunk']) + && (! in_array($index['element'], $alwaysIncludeElements, true)) ) { continue; } @@ -316,8 +316,8 @@ private function processCombinedJsonIndex(): array $indexes = $this->indexRepository->getIndexesWithDuplicates(); foreach ($indexes as $index) { if ( - (! in_array($index['element'], $alwaysIncludeElements, true)) - && (! $index['chunk']) + (! $index['chunk']) + && (! in_array($index['element'], $alwaysIncludeElements, true)) ) { continue; }