Full-Text Search
SurrealDB supports full-text search through DEFINE INDEX ... SEARCH. UnrealORM exposes this via Index.define with search: true.
Define a search index
Section titled “Define a search index”import { Table, Field, Index } from 'unreal-orm';
class Post extends Table.normal({ name: 'post', schemafull: true, fields: { title: Field.string(), content: Field.string(), },}) {}
const PostSearchIndex = Index.define(() => Post, { name: 'post_search_idx', fields: ['title', 'content'], search: true, analyzer: 'english', bm25: true, highlights: true,});Query the index
Section titled “Query the index”Use SurrealQL’s full-text operators in a surql template:
const posts = await Post.select(db, { where: surql`title @@ 'surreal' OR content @@ 'surreal'`,});Limitations
Section titled “Limitations”UnrealORM does not generate full-text analyzers. Define them with raw SurrealQL if you need custom tokenizers:
await db.query(surql`DEFINE ANALYZER english TOKENIZERS blank,class FILTERS lowercase,snowball(english)`);See the SurrealDB full-text search documentation for more details on operators and analyzers.