Skip to content

Commit 01de848

Browse files
committed
Search indexes: Fix missing search entries (with duplicated ids - requires changes on web-php to use new indexes)
1 parent 94f1882 commit 01de848

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

phpdotnet/phd/IndexRepository.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class IndexRepository
55
{
66
private array $indexes = [];
7+
private array $indexesDuped = [];
78
private array $children = [];
89
private array $refs = [];
910
private array $vars = [];
@@ -162,6 +163,16 @@ protected function SQLiteIndex($context, $index, $id, $filename, $parent, $sdesc
162163
];
163164
}
164165

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

phpdotnet/phd/Package/PHP/Web.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ protected function writeJsonIndex() {
247247
json_encode($descriptions)
248248
);
249249
$this->outputHandler->v("Index written", VERBOSE_FORMAT_RENDERING);
250+
251+
$entries = $this->processCombinedJsonIndex();
252+
file_put_contents(
253+
$this->getOutputDir() . "search-combined.json",
254+
json_encode($entries)
255+
);
256+
$entries = 'var localSearchIndexes = '. json_encode($entries) .';';
257+
file_put_contents(
258+
$this->getOutputDir() . "search-combined.js",
259+
$entries
260+
);
261+
$this->outputHandler->v("Combined Index written", VERBOSE_FORMAT_RENDERING);
250262
}
251263

252264
/**
@@ -290,6 +302,80 @@ private function processJsonIndex(): array {
290302
return [$entries, $descriptions];
291303
}
292304

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

0 commit comments

Comments
 (0)