Skip to content

Commit

Permalink
docs: Update 3.search.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Oct 27, 2023
1 parent f40e1a1 commit 40a2e5d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions docs/content/2.usage/3.search.md
@@ -1,12 +1,13 @@
# Search

With some simple configuration and a composable, you can add search to your Nuxt Content site.
---
title: Search
description: With some simple configuration and a composable, you can add search to your Nuxt Content site.
---

## Usage

First, you need to enable search in the `nuxt.config.js` file:
First, you need to enable the search feature in your `nuxt.config.ts`:

```js [nuxt.config.js]
```js [nuxt.config.ts]
export default defineNuxtConfig({
content: {
experimental: {
Expand All @@ -16,15 +17,15 @@ export default defineNuxtConfig({
})
```

::alert{type="info"}
You can use the search feature with any [Nuxt Content source](/api/configuration#sources). You can also enable or not the [document-driven feature](/guide/writing/document-driven).
::callout
You can use the search feature with any [Nuxt Content source](/get-started/configuration#sources). You can also enable or not the [document-driven feature](/document-driven/introduction).
::

## Search

You can use the `searchContent` composable to search in your `content` directory:
You can use the [`searchContent`](/composables/search-content) composable to search in your `content` directory:

```vue
```vue [app.vue]
<script lang="ts" setup>
const search = ref('')
Expand All @@ -40,17 +41,17 @@ const results = searchContent(search)
</template>
```

By default, the `searchContent` composable will used an indexed search. This mean that the search will be faster and the API response smaller and optimized **only usable by [`miniSearch`](https://lucaong.github.io/minisearch/)**.
By default, the [`searchContent`](/composables/search-content) composable will used an indexed search. This mean that the search will be faster and the API response smaller and optimized **only usable by [`miniSearch`](https://lucaong.github.io/minisearch/)**.

::alert{type="info"}
::callout
Internally, the search feature, both `searchContent` and `/api/indexed-search.ts` endpoint, use [`miniSearch`](https://lucaong.github.io/minisearch/).
::

## Simple Search

If needed, you can disable the indexed search and use a simple search instead:

```js [nuxt.config.js]
```ts [nuxt.config.ts]
export default defineNuxtConfig({
content: {
experimental: {
Expand All @@ -68,7 +69,7 @@ Remember that the simple search is **slower** and the API response **bigger**. Y

Using the simple search, aka non-indexed search, you can use the tool of your choice to search in the API response. For example, you can use [`fuse.js`](https://fusejs.io/) with the integration of [`@vueuse/integrations`](https://vueuse.org/integrations/useFuse/#usefuse):

```ts
```ts [composables/custom-search-content.ts]
export default async function customSearchContent(search: Ref<string>) {
const runtimeConfig = useRuntimeConfig()
const { integrity, api } = runtimeConfig.public.content
Expand All @@ -83,4 +84,4 @@ export default async function customSearchContent(search: Ref<string>) {

## Configuration

Please, read the [configuration section](../../4.api/3.configuration.md#search) to learn more about the search configuration.
Please, read the [configuration section](/get-started/configuration#search) to learn more about the search options.

0 comments on commit 40a2e5d

Please sign in to comment.