8000 Avoid indexing topics for singleton topics. (#466) · joernalraun/python-editor-next@f1ea1f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1ea1f2

Browse files
Avoid indexing topics for singleton topics. (microbit-foundation#466)
1 parent 573622f commit f1ea1f2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/documentation/search/search.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*/
66
import lunr from "lunr";
77
import { blocksToText } from "./blocks-to-text";
8-
import { ApiDocsEntry, ApiDocsResponse } from "../../language-server/apidocs";
9-
import { Toolkit } from "../explore/model";
8+
import type {
9+
ApiDocsEntry,
10+
ApiDocsResponse,
11+
} from "../../language-server/apidocs";
12+
import type { Toolkit, ToolkitTopic } from "../explore/model";
1013
import {
1114
Extracts,
1215
IndexMessage,
@@ -113,12 +116,14 @@ const defaultString = (string: string | undefined): string => {
113116
const exploreSearchableContent = (toolkit: Toolkit): SearchableContent[] => {
114117
const content: SearchableContent[] = [];
115118
toolkit.contents?.forEach((t) => {
116-
content.push({
117-
id: t.slug.current,
118-
title: t.name,
119-
containerTitle: t.name,
120-
content: t.subtitle + ".\n\n" + blocksToText(t.introduction),
121-
});
119+
if (!isSingletonTopic(t)) {
120+
content.push({
121+
id: t.slug.current,
122+
title: t.name,
123+
containerTitle: t.name,
124+
content: t.subtitle + ".\n\n" + blocksToText(t.introduction),
125+
});
126+
}
122127
t.contents?.forEach((e) => {
123128
const contentString = blocksToText(e.content);
124129
const detailContentString = blocksToText(e.detailContent);
@@ -231,3 +236,8 @@ export class SearchWorker {
231236
return this.current!;
232237
}
233238
}
239+
240+
// We have some topics that contain a single item with the same id.
241+
// There's no sense indexing the topic itself in those cases.
242+
const isSingletonTopic = (t: ToolkitTopic): boolean =>
243+
t.contents?.length === 1 && t.contents[0].slug.current === t.slug.current;

0 commit comments

Comments
 (0)
0