pub struct DefineIndex { /* private fields */ }Expand description
Builds a DEFINE INDEX statement — plain, composite, UNIQUE, full-text
(SEARCH), or vector (HNSW/MTREE) indexes.
// DEFINE INDEX IF NOT EXISTS email_idx ON TABLE user FIELDS email UNIQUE
DefineIndex::new("email_idx", "user").field("email").unique().to_surrealql();
// composite, vector
DefineIndex::new("name_idx", "user").fields(["first", "last"]).to_surrealql();
DefineIndex::new("emb_idx", "doc").field("embedding").hnsw(128, "COSINE").to_surrealql();Implementations§
Source§impl DefineIndex
impl DefineIndex
Sourcepub fn new(name: impl Into<String>, table: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self
Begin DEFINE INDEX IF NOT EXISTS <name> ON TABLE <table>.
Sourcepub fn fields<I, S>(self, names: I) -> Self
pub fn fields<I, S>(self, names: I) -> Self
Add several indexed fields/columns (a composite index).
Sourcepub fn search(self, analyzer: impl Into<String>) -> Self
pub fn search(self, analyzer: impl Into<String>) -> Self
A full-text FULLTEXT ANALYZER <analyzer> index (SurrealDB 3.x; the
pre-3.x SEARCH keyword is no longer accepted). Append further options
(BM25, HIGHLIGHTS, …) with raw — BM25 is required for
search::score() to be available.
Sourcepub fn hnsw(self, dimension: u32, dist: impl Into<String>) -> Self
pub fn hnsw(self, dimension: u32, dist: impl Into<String>) -> Self
An HNSW vector index of the given dimension and distance function
(e.g. "COSINE", "EUCLIDEAN").
Sourcepub fn mtree(self, dimension: u32, dist: impl Into<String>) -> Self
pub fn mtree(self, dimension: u32, dist: impl Into<String>) -> Self
An MTREE vector index of the given dimension and distance function.
Sourcepub fn raw(self, tail: impl Into<String>) -> Self
pub fn raw(self, tail: impl Into<String>) -> Self
Set a verbatim trailing clause (the escape hatch for index options somnia
doesn’t model), e.g. "SEARCH ANALYZER ascii BM25 HIGHLIGHTS".
Sourcepub fn concurrently(self) -> Self
pub fn concurrently(self) -> Self
Build the index CONCURRENTLY (non-blocking).
pub fn to_surrealql(&self) -> String
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DefineIndex
impl RefUnwindSafe for DefineIndex
impl Send for DefineIndex
impl Sync for DefineIndex
impl Unpin for DefineIndex
impl UnsafeUnpin for DefineIndex
impl UnwindSafe for DefineIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more