From ac9dfb01351b7d47a93726346711a9610a51fe05 Mon Sep 17 00:00:00 2001 From: F F Date: Tue, 14 Feb 2023 12:11:48 -0600 Subject: [PATCH] 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 --- packages/web/src/lib/search/Search.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/web/src/lib/search/Search.ts b/packages/web/src/lib/search/Search.ts index 176849dd..91aba24d 100644 --- a/packages/web/src/lib/search/Search.ts +++ b/packages/web/src/lib/search/Search.ts @@ -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 = { @@ -68,7 +71,10 @@ 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(' ') } ]) ); @@ -76,7 +82,10 @@ export class Search { 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"]; @@ -84,7 +93,10 @@ export class Search { builder.add({ slug, title: adr.title, - verbatim: adr.verbatim + body: adr.body, + status: adr.status, + tags: adr.tags, + deciders: adr.deciders, }); }); });