Skip to content

Commit ac9dfb0

Browse files
committed
Add additional fields which a user can use to search
Note: this skipped the lint-staged step because it airbnb's dependency has a main field set in the package json and the step wont pass
1 parent 37187fc commit ac9dfb0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/web/src/lib/search/Search.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import lunr from "lunr";
44

55
type AdrForSearch = {
66
title: string;
7-
verbatim: string; // body without Markdown or HTML tags, without recurring headers
7+
body: string; // body without Markdown or HTML tags, without recurring headers
8+
status: string;
9+
tags: string;
10+
deciders: string;
811
};
912

1013
export type SerializedIndex = {
@@ -68,23 +71,32 @@ export class Search {
6871
adr.slug,
6972
{
7073
title: adr.title || "Untitled",
71-
verbatim: adr.body.enhancedMdx // TODO: remove tags (https://github.com/thomvaill/log4brains/issues/5)
74+
body: adr.body.enhancedMdx, // TODO: remove tags (https://github.com/thomvaill/log4brains/issues/5)
75+
status: adr.status || 'draft',
76+
tags: (adr.tags || []).join(' '),
77+
deciders: adr.lastEditAuthor + (adr.deciders || []).join(' ')
7278
}
7379
])
7480
);
7581

7682
const index = lunr((builder) => {
7783
builder.ref("slug");
7884
builder.field("title", { boost: 1000 });
79-
builder.field("verbatim");
85+
builder.field("body");
86+
builder.field("status", {boost: 50});
87+
builder.field("tags", {boost: 50});
88+
builder.field("deciders");
8089
// eslint-disable-next-line no-param-reassign
8190
builder.metadataWhitelist = ["position"];
8291

8392
adrsForSearch.forEach((adr, slug) => {
8493
builder.add({
8594
slug,
8695
title: adr.title,
87-
verbatim: adr.verbatim
96+
body: adr.body,
97+
status: adr.status,
98+
tags: adr.tags,
99+
deciders: adr.deciders,
88100
});
89101
});
90102
});

0 commit comments

Comments
 (0)