2323
2424import cn from 'clsx' ;
2525// flexsearch types are incorrect, they were overwritten in tsconfig.json
26- import FlexSearch from 'flexsearch' ;
26+ import { Document } from 'flexsearch' ;
2727import { useRouter } from 'next/router' ;
2828import type { SearchData } from 'nextra' ;
2929import type { ReactElement , ReactNode } from 'react' ;
@@ -36,38 +36,30 @@ import { SearchResult } from './types';
3636// Diff: Inlined definitions
3737export const DEFAULT_LOCALE = 'en-US' ;
3838
39- type SectionIndex = FlexSearch . Document <
40- {
39+ type SectionIndex = {
4140 id : string ;
4241 url : string ;
4342 title : string ;
4443 pageId : string ;
4544 content : string ;
4645 display ?: string ;
47- } ,
48- [ 'title' , 'content' , 'url' , 'display' ]
49- > ;
46+ }
5047
51- type PageIndex = FlexSearch . Document <
52- {
48+ type PageIndex = {
5349 id : number ;
5450 title : string ;
5551 content : string ;
56- } ,
57- [ 'title' ]
58- > ;
52+ }
5953
6054// Diff: Additional index for blog posts
61- type BlogIndex = FlexSearch . Document <
55+ type BlogIndex =
6256 {
6357 id : number ;
6458 title : string ;
6559 content : string ;
6660 url : string ;
6761 summary : string ;
68- } ,
69- [ 'title' , 'url' , 'summary' ]
70- > ;
62+ }
7163
7264type Result = {
7365 _page_rk : number ;
@@ -79,11 +71,13 @@ type Result = {
7971
8072// This can be global for better caching.
8173const indexes : {
82- [ locale : string ] : [ PageIndex , SectionIndex ] ;
74+ // tuple is PageIndex, SectionIndex
75+ [ locale : string ] : [ Document , Document ] ;
8376} = { } ;
8477
8578// Diff: Index for blog posts
86- const blogIndex : BlogIndex = new FlexSearch . Document ( {
79+ // Associated type is BlogIndex
80+ const blogIndex = new Document ( {
8781 cache : 100 ,
8882 tokenize : 'forward' ,
8983 document : {
@@ -134,7 +128,8 @@ const loadIndexesImpl = async (
134128 // Diff: Load blog data
135129 const blogData = await loadBlogData ( basePath ) ;
136130
137- const pageIndex : PageIndex = new FlexSearch . Document ( {
131+ // Associated type is PageIndex
132+ const pageIndex = new Document ( {
138133 cache : 100 ,
139134 tokenize : 'full' ,
140135 document : {
@@ -149,7 +144,8 @@ const loadIndexesImpl = async (
149144 } ,
150145 } ) ;
151146
152- const sectionIndex : SectionIndex = new FlexSearch . Document ( {
147+ // Associated type is SectionIndex
148+ const sectionIndex = new Document ( {
153149 cache : 100 ,
154150 tokenize : 'full' ,
155151 document : {
@@ -232,7 +228,7 @@ export function Flexsearch({
232228
233229 // Show the results for the top 5 pages
234230 const pageResults =
235- pageIndex . search < true > ( search , 5 , {
231+ pageIndex . search ( search , 5 , {
236232 enrich : true ,
237233 suggest : true ,
238234 } ) [ 0 ] ?. result || [ ] ;
@@ -247,7 +243,7 @@ export function Flexsearch({
247243
248244 // Show the top 5 results for each page
249245 const sectionResults =
250- sectionIndex . search < true > ( search , 5 , {
246+ sectionIndex . search ( search , 5 , {
251247 enrich : true ,
252248 suggest : true ,
253249 tag : `page_${ result . id } ` ,
@@ -324,7 +320,7 @@ export function Flexsearch({
324320 } ) ) ;
325321
326322 const blogResults =
327- blogIndex . search < true > ( search , 5 , {
323+ blogIndex . search ( search , 5 , {
328324 enrich : true ,
329325 suggest : true ,
330326 } ) [ 0 ] ?. result || [ ] ;
0 commit comments