File tree 2 files changed +29
-21
lines changed
2 files changed +29
-21
lines changed Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server'
2
+ import Fuse from 'fuse.js'
3
+ import { readIndex } from '../../../utils/posts.js'
4
+
5
+ export const runtime = 'edge'
6
+
7
+ // Define the handler for GET requests
8
+ export async function GET ( req : Request ) {
9
+ const { searchParams } = new URL ( req . url )
10
+ const q = searchParams . get ( 'q' ) ?? ''
11
+
12
+ const search = Array . isArray ( q ) ? q . join ( ' ' ) : q
13
+
14
+ const index = await readIndex ( )
15
+
16
+ const fuse = new Fuse ( index , {
17
+ keys : [ 'text' ] ,
18
+ includeScore : true ,
19
+ includeMatches : true ,
20
+ minMatchCharLength : 2
21
+ } )
22
+
23
+ const results = fuse . search ( search ) . slice ( 0 , 5 )
24
+
25
+ console . log ( results )
26
+
27
+ // Return the results as a JSON response
28
+ return NextResponse . json ( results )
29
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments