Skip to content

Commit

Permalink
Add additional fields which a user can use to search
Browse files Browse the repository at this point in the history
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
  • Loading branch information
my8bird committed Feb 14, 2023
1 parent 37187fc commit ac9dfb0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/web/src/lib/search/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import lunr from "lunr";

type AdrForSearch = {
title: string;
verbatim: string; // body without Markdown or HTML tags, without recurring headers
body: string; // body without Markdown or HTML tags, without recurring headers
status: string;
tags: string;
deciders: string;
};

export type SerializedIndex = {
Expand Down Expand Up @@ -68,23 +71,32 @@ export class Search {
adr.slug,
{
title: adr.title || "Untitled",
verbatim: adr.body.enhancedMdx // TODO: remove tags (https://github.com/thomvaill/log4brains/issues/5)
body: adr.body.enhancedMdx, // TODO: remove tags (https://github.com/thomvaill/log4brains/issues/5)
status: adr.status || 'draft',
tags: (adr.tags || []).join(' '),
deciders: adr.lastEditAuthor + (adr.deciders || []).join(' ')
}
])
);

const index = lunr((builder) => {
builder.ref("slug");
builder.field("title", { boost: 1000 });
builder.field("verbatim");
builder.field("body");
builder.field("status", {boost: 50});
builder.field("tags", {boost: 50});
builder.field("deciders");
// eslint-disable-next-line no-param-reassign
builder.metadataWhitelist = ["position"];

adrsForSearch.forEach((adr, slug) => {
builder.add({
slug,
title: adr.title,
verbatim: adr.verbatim
body: adr.body,
status: adr.status,
tags: adr.tags,
deciders: adr.deciders,
});
});
});
Expand Down

0 comments on commit ac9dfb0

Please sign in to comment.