Skip to content

Commit 264c65b

Browse files
authored
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
1 parent deb7d81 commit 264c65b

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

phpdotnet/phd/IndexRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ protected function SQLiteIndex($context, $index, $id, $filename, $parent, $sdesc
162162
];
163163
}
164164

165+
public function getIndexesWithDuplicates(): array
166+
{
167+
$results = $this->db->query('SELECT docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next, chunk FROM ids');
168+
$indexes = [];
169+
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
170+
$indexes[] = $row;
171+
}
172+
return $indexes;
173+
}
174+
165175
private static function SQLiteFinal($context): mixed {
166176
return $context;
167177
}

phpdotnet/phd/Package/PHP/Web.php

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,40 @@ protected function writeJsonIndex() {
249249
json_encode($descriptions)
250250
);
251251
$this->outputHandler->v("Index written", VERBOSE_FORMAT_RENDERING);
252+
253+
$entries = $this->processCombinedJsonIndex();
254+
file_put_contents(
255+
$this->getOutputDir() . "search-combined.json",
256+
json_encode($entries)
257+
);
258+
$entries = 'var localSearchIndexes = '. json_encode($entries) .';';
259+
file_put_contents(
260+
$this->getOutputDir() . "search-combined.js",
261+
$entries
262+
);
263+
$this->outputHandler->v("Combined Index written", VERBOSE_FORMAT_RENDERING);
252264
}
253265

254266
/**
255267
* Processes the index to extract entries and descriptions. These are
256268
* used to generate the search index and the descriptions JSON files.
257269
*/
258270
private function processJsonIndex(): array {
271+
$alwaysIncludeElements = [
272+
'refentry',
273+
'stream_wrapper',
274+
'phpdoc:classref',
275+
'phpdoc:exceptionref',
276+
'phpdoc:varentry',
277+
];
278+
259279
$entries = [];
260280
$descriptions = [];
261281
foreach($this->indexes as $id => $index) {
262-
if (!$index["chunk"]) {
282+
if (
283+
(! $index['chunk'])
284+
&& (! in_array($index['element'], $alwaysIncludeElements, true))
285+
) {
263286
continue;
264287
}
265288

@@ -281,6 +304,80 @@ private function processJsonIndex(): array {
281304
return [$entries, $descriptions];
282305
}
283306

307+
private function processCombinedJsonIndex(): array
308+
{
309+
$alwaysIncludeElements = [
310+
'refentry',
311+
'stream_wrapper',
312+
'phpdoc:classref',
313+
'phpdoc:exceptionref',
314+
'phpdoc:varentry',
315+
];
316+
317+
$entries = [];
318+
$indexes = $this->indexRepository->getIndexesWithDuplicates();
319+
foreach ($indexes as $index) {
320+
if (
321+
(! $index['chunk'])
322+
&& (! in_array($index['element'], $alwaysIncludeElements, true))
323+
) {
324+
continue;
325+
}
326+
327+
if ($index["sdesc"] === "" && $index["ldesc"] !== "") {
328+
$index["sdesc"] = $index["ldesc"];
329+
$bookOrSet = $this->findParentBookOrSet($index['parent_id']);
330+
if ($bookOrSet) {
331+
$index["ldesc"] = Format::getLongDescription(
332+
$bookOrSet['docbook_id']
333+
);
334+
}
335+
}
336+
337+
$nameParts = explode('::', $index['sdesc']);
338+
$methodName = array_pop($nameParts);
339+
340+
if (str_contains('wrapper', $index['filename'])) {
341+
print "Combined index: adding " . $index['filename'] . " :: " . $index['sdesc'] . "\n";
342+
}
343+
344+
$type = 'General';
345+
switch ($index['element']) {
346+
case "phpdoc:varentry":
347+
$type = "Variable";
348+
break;
349+
350+
case "refentry":
351+
$type = "Function";
352+
break;
353+
354+
case "phpdoc:exceptionref":
355+
$type = "Exception";
356+
break;
357+
358+
case "phpdoc:classref":
359+
$type = "Class";
360+
break;
361+
362+
case "set":
363+
case "book":
364+
case "reference":
365+
$type = "Extension";
366+
break;
367+
}
368+
369+
$entries[] = [
370+
'id' => $index['filename'],
371+
'name' => $index['sdesc'],
372+
'description' => html_entity_decode($index['ldesc']),
373+
'tag' => $index['element'],
374+
'type' => $type,
375+
'methodName' => $methodName,
376+
];
377+
}
378+
return $entries;
379+
}
380+
284381
/**
285382
* Finds the closest parent book or set in the index hierarchy.
286383
*/

tests/render/render_001.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ require_once __DIR__ . "/../../render.php";
1616
%s[%d:%d:%d - Rendering Format ]%s Starting PHP-Web rendering
1717
%s[%d:%d:%d - Rendering Format ]%s Writing search indexes..
1818
%s[%d:%d:%d - Rendering Format ]%s Index written
19+
%s[%d:%d:%d - Rendering Format ]%s Combined Index written
1920
%s[%d:%d:%d - Rendering Format ]%s Finished rendering

0 commit comments

Comments
 (0)