---
title: "nuxt-backend/search"
description: "Every export of nuxt-backend/search, with its signature and where it is defined."
canonical_url: "https://nuxt-backend.dev/docs/reference/api/search"
---
# nuxt-backend/search

## Interfaces

### SearchConfig

Defined in: [src/convex/integrations/search.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts)

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-dm-1">
        
      </a>
      
       <code>
        DM
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-t-1">
        
      </a>
      
       <code>
        T
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        TableNamesInDataModel
      </code>
      
      <<code>
        DM
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-i">
        
      </a>
      
       <code>
        I
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        IndexName
      </code>
      
      <<code>
        DM
      </code>
      
      , <code>
        T
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="table">
        
      </a>
      
       <code>
        table
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
    </td>
    
    <td>
      The table to search.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts" rel="nofollow">
        src/convex/integrations/search.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="index">
        
      </a>
      
       <code>
        index
      </code>
    </td>
    
    <td>
      <code>
        I
      </code>
    </td>
    
    <td>
      The <code>
        searchIndex
      </code>
      
       name on that table.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts" rel="nofollow">
        src/convex/integrations/search.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="searchfield">
        
      </a>
      
       <code>
        searchField
      </code>
    </td>
    
    <td>
      <code>
        NamedSearchIndex
      </code>
      
      <<code>
        TableInfo
      </code>
      
      <<code>
        DM
      </code>
      
      , <code>
        T
      </code>
      
      >, <code>
        I
      </code>
      
      >[<code>
        "searchField"
      </code>
      
      ]
    </td>
    
    <td>
      The search field declared on the index.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts" rel="nofollow">
        src/convex/integrations/search.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="defaultlimit">
        
      </a>
      
       <code>
        defaultLimit?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Default number of results when the caller omits <code>
        limit
      </code>
      
       (default 20).
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts" rel="nofollow">
        src/convex/integrations/search.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

## Functions

### search()

```ts
function search<DM, T>(ctx, table): {
  withSearchIndex<I>(index): SearchIndexBound<DM, T, I>;
};
```

Defined in: [src/convex/integrations/search.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts)

A fluent, type-safe builder over Convex's native full-text search. Index
names, search fields, and `eq` filter fields are all checked against your
schema's `searchIndex` definitions.

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-dm">
        
      </a>
      
       <code>
        DM
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-t">
        
      </a>
      
       <code>
        T
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        string
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      { <code>
        db
      </code>
      
      : <code>
        GenericDatabaseReader
      </code>
      
      <<code>
        DM
      </code>
      
      >; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ctx.db
      </code>
    </td>
    
    <td>
      <code>
        GenericDatabaseReader
      </code>
      
      <<code>
        DM
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        table
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Returns

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        withSearchIndex()
      </code>
    </td>
    
    <td>
      (<code>
        index
      </code>
      
      ) => <code>
        SearchIndexBound
      </code>
      
      <<code>
        DM
      </code>
      
      , <code>
        T
      </code>
      
      , <code>
        I
      </code>
      
      >
    </td>
    
    <td>
      Pick the <code>
        searchIndex
      </code>
      
       (by name) to query.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts" rel="nofollow">
        src/convex/integrations/search.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

#### Example

```ts
const results = await search(ctx, 'messages')
  .withSearchIndex('search_text')
  .search('text', term)
  .eq('userId', userId)
  .take(20)
```

---

### defineSearch()

```ts
function defineSearch<DM, T, I>(query, config): RegisteredQuery<"public", {
  query: string;
  limit?: number;
}, Promise<Doc<DM, T>[]>>;
```

Defined in: [src/convex/integrations/search.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/search.ts)

Define a ready-to-call Convex search query from a search-index config. The
generated query takes `{ query: string, limit?: number }` and returns the
matching documents — pair it with the `useSearch` composable on the client.

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-dm-2">
        
      </a>
      
       <code>
        DM
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-t-2">
        
      </a>
      
       <code>
        T
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        string
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-i-1">
        
      </a>
      
       <code>
        I
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        string
      </code>
      
       | <code>
        number
      </code>
      
       | <code>
        symbol
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        query
      </code>
    </td>
    
    <td>
      <code>
        QueryBuilder
      </code>
      
      <<code>
        DM
      </code>
      
      , <code>
        "public"
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        config
      </code>
    </td>
    
    <td>
      <a href="#searchconfig">
        <code>
          SearchConfig
        </code>
      </a>
      
      <<code>
        DM
      </code>
      
      , <code>
        T
      </code>
      
      , <code>
        I
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Returns

`RegisteredQuery`<`"public"`, {
`query`: `string`;
`limit?`: `number`;
}, `Promise`<`Doc`<`DM`, `T`><span>



</span>

>>

#### Example

```ts
import { defineSearch } from 'nuxt-backend/search'
import { query } from './_generated/server'

export const searchMessages = defineSearch(query, {
  table: 'messages',
  index: 'search_text',
  searchField: 'text',
})
```


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
