Composables

searchContent()

Used to search in your content directory.

searchContent()

Used to search in your content directory.

const input = ref('')
const results = searchContent(input)

Parameters

KeyTypeDefaultDescription
searchMaybeRefOrGetter<string>The search input
optionsSearchContentOptions{}The options
options.miniSearchMaybeRefOrGetter<MiniSearchOptions<T>>The options passed to miniSearch
options.fetchMaybeRefOrGetter<UseFetchOptions<string | T>>The options passed to useFetch

MiniSearchOptions

You can easily define the miniSearch options by using the defineMiniSearchOptions composable:

const miniSearchOptions = defineMiniSearchOptions({
  fields: ['title', 'description', 'body']
})

Using these options allows you to modify how the search is performed. You can change the fields that are searched, the weight of each field, and more.

Only available when using the simple search, aka non-indexed search.

UseFetchOptions

An option is provided to customize the behavior of the useFetch composable used internally to only fetch the search content on client and lazy. This could avoid fetching the content on SSR and adding content to the _payload.josn file improving the performance of your app since _payload is loaded for hydration.