From a64b8008e51a4337076d807c85b80a9888d2b792 Mon Sep 17 00:00:00 2001 From: Nathan Landis Date: Fri, 5 Aug 2022 12:39:51 -0500 Subject: [PATCH] Add more fields to search on 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 --- packages/web/src/lib/search/Search.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/web/src/lib/search/Search.ts b/packages/web/src/lib/search/Search.ts index 176849dd..d0f72023 100644 --- a/packages/web/src/lib/search/Search.ts +++ b/packages/web/src/lib/search/Search.ts @@ -67,8 +67,11 @@ 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(" ") } ]) ); @@ -76,16 +79,21 @@ export class Search { 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);