Skip to content

Commit

Permalink
Add more fields to search on
Browse files Browse the repository at this point in the history
Adding tags, status, and deciders and searchable fields.  Also, renamed verbatim to body so that in the search bar the user can easy search the body of the ADR.

These searches are now available powered by the luna package.
 * body: Text from the body
 * deciders: Tony
* tags: database
* status: draft
  • Loading branch information
my8bird committed Feb 14, 2023
1 parent 37187fc commit a64b800
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/web/src/lib/search/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,33 @@ export class Search {
adrs.map((adr) => [
adr.slug,
{
title: adr.title || "Untitled",
verbatim: adr.body.enhancedMdx // TODO: remove tags (https://github.com/thomvaill/log4brains/issues/5)
title: adr.title || "Untitled",
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("tags", {boost: 50 });
builder.field("status", {boost: 50 });
builder.field("body");
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
});
builder.add({
slug,
title: adr.title,
body: adr.body,
status: adr.status,
deciders: adr.deciders,
tags: adr.tags
});
});
});
return new Search(index, adrsForSearch);
Expand Down

0 comments on commit a64b800

Please sign in to comment.