#Full text search across tables

3 messages · Page 1 of 1 (latest)

uneven magnet
#

In Convex, when you want to do full text search across database tables, do you typically create a dedicated table for searching?

high lanternBOT
#

Hi @uneven magnet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, Convex does not explicitly mention the ability to perform full text search across multiple tables. Full text search in Convex is performed on specific fields within a single table.

To perform a full text search, you need to define a search index on the table you want to search. This is done as part of your Convex schema. The search index definition consists of a unique name, a searchField which is the field that will be indexed for full text search, and optionally, a list of filterFields which are additional fields that are indexed for fast equality filtering within your search index.

Here is an example of how to define a search index on a table:

import { defineSchema, defineTable } from "convex/server";  
import { v } from "convex/values";  
  
export default defineSchema({  
  messages: defineTable({  
    body: v.string(),  
    channel: v.string(),  
  }).searchIndex("search_body", {  
    searchField: "body",  
    filterFields: ["channel"],  
  }),  
});  

In this example, a search index named "search_body" is defined on the "messages" table, with "body" as the search field and "channel" as the filter field.

If you need to search across multiple tables, you would likely need to perform separate search queries on each table and then combine the results in your application code.

For more information, you can refer to the Convex documentation on full text search (https://docs.convex.dev/search/text-search).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: