Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 SDK. For use with version 1.x, see here.

Full-Text Search

SurrealDB supports full-text search through DEFINE INDEX ... SEARCH. UnrealORM exposes this via Index.define with search: true.

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,
});

Use SurrealQL’s full-text operators in a surql template:

const posts = await Post.select(db, {
where: surql`title @@ 'surreal' OR content @@ 'surreal'`,
});

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.