diff --git a/src/components/NavigationBar/SearchContainer.svelte b/src/components/NavigationBar/SearchContainer.svelte index 94643685..c913b215 100644 --- a/src/components/NavigationBar/SearchContainer.svelte +++ b/src/components/NavigationBar/SearchContainer.svelte @@ -64,7 +64,8 @@ categories={[ SearchIndexCategory.Politicians, SearchIndexCategory.Votings, - SearchIndexCategory.Bills + SearchIndexCategory.Bills, + SearchIndexCategory.Promises ]} name="navSearch" type="text" diff --git a/src/lib/search.ts b/src/lib/search.ts index b827a8da..6c2a2f46 100644 --- a/src/lib/search.ts +++ b/src/lib/search.ts @@ -94,6 +94,16 @@ export function search( url: '/bills/explore?proposername=' + proposer.item.name }) ) + : undefined, + promises: searchIndexes.promises + ? getScoredAndHighlightedResultItems(queries, searchIndexes.promises, keepTopN).map( + (promise) => ({ + heading: promise.item.name.slice(0, 16), + headingHighlight: highlight ? promise.highlightedName : undefined, + promiseStatus: promise.item.status, + url: '/promises/' + promise.item.id + }) + ) : undefined }; } @@ -103,7 +113,7 @@ function getScoredAndHighlightedResultItems( searchIndexes: T[], keepTopN: number ) { - return postCalcuateScore(calculateScore(queries, searchIndexes), keepTopN); + return postCalculateScore(calculateScore(queries, searchIndexes), keepTopN); } /** @@ -179,7 +189,7 @@ export function calculateScore( * @param keepTopN - The number of top candidates to return. * @returns - The list of top candidates with highlighted matched indices. */ -function postCalcuateScore( +function postCalculateScore( candidates: ScoreResultItem[], keepTopN = 5 ): ScoreAndHighlightResultItem[] { diff --git a/src/models/search.ts b/src/models/search.ts index f954cca3..e56bfe72 100644 --- a/src/models/search.ts +++ b/src/models/search.ts @@ -5,10 +5,10 @@ export enum SearchIndexCategory { Politicians = 'politicians', Bills = 'bills', Votings = 'votings', - BillProposers = 'billProposers' + BillProposers = 'billProposers', + Promises = 'promises' } -// TODO - เช็คว่าตัวอื่นต้องใช้อะไรในการ Link ไปหน้านั้นๆ export interface SearchIndexes { [SearchIndexCategory.Politicians]?: { id: string; @@ -30,6 +30,11 @@ export interface SearchIndexes { description: string; proposedBillsCount: number; }[]; + [SearchIndexCategory.Promises]?: { + id: string; + name: string; + status: PromiseStatus; + }[]; } interface BaseSearchResultItem { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index f58c571c..c94d6ba5 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -124,6 +124,7 @@ title="คำสัญญาทางการเมือง" icon={PromiseIcon} searchPlaceholder="ค้นหาด้วยคำสัญญา เช่น กระเป๋าเงินดิจิทัล" + searchCategories={[SearchIndexCategory.Promises]} class="bg-ui-white" > ({ + id, + name: statements[0], + status + }) + ); + + return createJSONFileResponse(indexes); + } + default: error(404); }