> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# Instant Search

**Publié le** : 2026-11-30
**Catégorie** : Features

Query Lynkow search from your Next.js site: a results page, a search-as-you-type box, multi-language results, commerce hits and scoped search profiles. Lynkow keeps the index in sync with every publish, update, archive and delete.

> **Reference** - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
> 
> - SDK: [`SearchService`](/sdk/services/sdk-search-service)
> - Types: [SDK Types](/sdk/types)
> - API: [Storefront: Search](/storefront-api/storefront-search)

## Prerequisites

- A Lynkow client in `@/lib/lynkow` ([Add Lynkow to an Existing Project](/sdk/getting-started/existing-project))
- Search turned on: in the dashboard, **Settings > Developers > Search**, tab **General**, switch **Enable Search**. Turning it on indexes all published content. While it is off, every search call fails with status 503.

## 1. Basic search

```typescript
import { lynkow } from '@/lib/lynkow'

const { data, meta } = await lynkow.search.search('pagination', {
  category: 'guides', // article category slug
  tag: 'forms',       // tag slug
  page: 1,
  limit: 10,          // the default profile caps it at 100
})
```

`data` holds the hits. `meta` carries `total`, `page`, `totalPages`, `perPage`, `query` and `processingTimeMs`. A typo such as `pagniation` still matches.

Every field of a hit is optional: the site chooses which fields are indexed and the profile which of them are returned. That includes `id` and `path`, so render a hit without a link when `path` is absent. The optional `_formatted` object carries the returned values with the matched text wrapped in `<em>`. Its values are not always strings, so check `typeof value === 'string'` and escape the text before rendering it as HTML.

## 2. Search page (Server Component)

```tsx
// app/search/page.tsx
import Link from 'next/link'
import { lynkow } from '@/lib/lynkow'

export default async function SearchPage({
  searchParams,
}: {
  searchParams: Promise<{ q?: string; page?: string }>
}) {
  const { q, page } = await searchParams

  const form = (
    <form action="/search">
      <input type="search" name="q" defaultValue={q} />
      <button type="submit">Search</button>
    </form>
  )
  if (!q) return form

  const { data, meta } = await lynkow.search.search(q, {
    page: Number(page) || 1,
    limit: 20,
  })
  const pageUrl = (n: number) => `/search?q=${encodeURIComponent(q)}&page=${n}`

  return (
    <main>
      {form}
      <p>{meta.total} results</p>
      <ul>
        {data.map((hit, index) => (
          <li key={hit.id ?? index}>
            {hit.path ? <Link href={hit.path}>{hit.title}</Link> : hit.title}
            {hit.excerpt && <p>{hit.excerpt}</p>}
          </li>
        ))}
      </ul>
      {meta.page > 1 && <Link href={pageUrl(meta.page - 1)}>Previous</Link>}
      {meta.page < meta.totalPages && <Link href={pageUrl(meta.page + 1)}>Next</Link>}
    </main>
  )
}
```

## 3. Search as you type (Client Component)

The client from `@/lib/lynkow` holds no secret, so it runs in the browser. The SDK never caches search results. Once the site has a domain, a browser call is accepted from that domain only: add `localhost` and your preview hostnames under **Settings > Developers > Storefront**, **Allowed origins**.

```tsx
'use client'

import { useEffect, useState } from 'react'
import type { SearchHit } from 'lynkow'
import { lynkow } from '@/lib/lynkow'

export function SearchBox() {
  const [query, setQuery] = useState('')
  const [hits, setHits] = useState<SearchHit[]>([])

  useEffect(() => {
    if (!query.trim()) {
      setHits([])
      return
    }
    let stale = false
    const timer = setTimeout(async () => {
      const { data } = await lynkow.search.search(query, { limit: 5 })
      if (!stale) setHits(data)
    }, 200)
    return () => {
      stale = true
      clearTimeout(timer)
    }
  }, [query])

  return (
    <div>
      <input type="search" value={query} onChange={(e) => setQuery(e.target.value)} />
      <ul>
        {hits.map((hit, index) => (
          <li key={hit.id ?? index}>
            {hit.path ? <a href={hit.path}>{hit.title}</a> : hit.title}
          </li>
        ))}
      </ul>
    </div>
  )
}
```

## 4. Multi-language search

```typescript
// French hits, plus the pages with no French version, served in another locale
const results = await lynkow.search.search('formulaire', { locale: 'fr' })

for (const hit of results.data) {
  if (hit.isFallback) {
    // hit.locale names the locale this hit is served in
  }
}

// French hits only
const strict = await lynkow.search.search('formulaire', { locale: 'fr', fallback: false })
```

Search follows the [fallback contract](/sdk/features/i18n#fallback-contract) of the other storefront reads. With a locale, every hit carries `locale` (the locale it is served in), `requestedLocale` and `isFallback`. A client created with a `locale` sends it on every search, and the option overrides it.

Without any locale, articles come back in every locale, each in its own, and each commerce page once, in the site default locale. On a single-language site, `locale` keeps only the hits in that locale, whatever `fallback` says.

## 5. Commerce results

Products, product categories and collections are left out of search by default. On a site with the product storefront on, the **General** tab shows a second switch, **Include products, collections and categories**. Turn it on to return them in the same ranked list as the articles.

A commerce hit's `type` tells it apart:

| `type` | `id` prefix | `title` |
| --- | --- | --- |
| `'product'` | `prod_` | Product title |
| `'product_category'` | `pcat_` | Category name |
| `'product_collection'` | `col_` | Collection title |


Its `path` is the public URL that [`paths.resolve()`](/sdk/advanced/catch-all-routes) recognises, and its `slug` is the one the matching `getBySlug()` accepts ([Product Catalog](/sdk/features/commerce-products)). It has no `excerpt`, `categories` or `tags`, and `category` or `tag` filters return no commerce hit. It carries `description` and `image` when the profile's **Displayed fields** list them.

```tsx
const LABELS: Record<string, string> = {
  product: 'Product',
  product_category: 'Category',
  product_collection: 'Collection',
}

{data.map((hit, index) => (
  <li key={hit.id ?? index}>
    {hit.type && LABELS[hit.type] && <span>{LABELS[hit.type]}</span>}
    {hit.path ? <Link href={hit.path}>{hit.title}</Link> : hit.title}
  </li>
))}
```

- A hit never carries a price or a stock level. Read the product with `lynkow.products.getBySlug(hit.slug)` to show one.
- Pass `market` (a market id, `mkt_...`) to leave out the products hidden in that market.
- A page marked noindex is still returned by site search. It is left out of the sitemap and of the [llms files](/sdk/advanced/llm-ready-content) only.

## 6. Search profiles

A profile is a named search with its own scope, fields and limits, created under **Settings > Developers > Search**, tab **Profiles**. Its **Content types** scope accepts the commerce types next to the article types: tick only `product`, `product_category` and `product_collection` for a catalog search. A profile with no type ticked searches every type. Tick **Public** to query it from your site.

```typescript
const products = await lynkow.search.searchByProfile('catalog', 'linen', { limit: 12 })

const profiles = await lynkow.search.listProfiles() // the site's public profiles
```

`searchByProfile()` takes the same options as `search()` and returns the same shape. It throws a `LynkowError` with code `NOT_FOUND` for an unknown slug and `FORBIDDEN` for a profile that is not public ([Error Handling](/sdk/advanced/error-handling)). A profile scoped to commerce types returns nothing while the commerce switch is off.

## 7. Search outside the SDK

The endpoint is public. AI agents and other clients can call it directly:

```bash
curl -s "https://api.lynkow.com/storefront/YOUR_SITE_ID/search?q=pagination&locale=en&limit=5"
```

When search is on and the site has a domain, Lynkow adds a `## Search` section describing this endpoint to its [llms.txt](/sdk/advanced/llm-ready-content). AI agents connected to the Lynkow MCP server get the same search through the `search_read` tool, action `query`.

## Next Steps

- [LLM-Ready Content](/sdk/advanced/llm-ready-content) - expose your content to AI assistants
- [Multi-language (i18n)](/sdk/features/i18n) - locales and the fallback contract
- [Product Catalog](/sdk/features/commerce-products) - product pages your commerce hits link to