27 lines
499 B
TypeScript
27 lines
499 B
TypeScript
import { Meilisearch, type SearchResponse } from 'meilisearch'
|
|
|
|
export async function createSearch({
|
|
query,
|
|
filter = undefined,
|
|
index,
|
|
sort,
|
|
env
|
|
}: {
|
|
query?: string
|
|
filter?: string
|
|
index: string
|
|
sort: string[]
|
|
env: Env
|
|
}): Promise<SearchResponse> {
|
|
const host = env.MEILI_HOST
|
|
const apiKey = env.MEILI_API_KEY
|
|
const client = new Meilisearch({ host, apiKey })
|
|
const index_ = client.index(index)
|
|
|
|
return index_.search(query, {
|
|
sort,
|
|
filter,
|
|
limit: 100
|
|
})
|
|
}
|