pub trait Engine: Send + Sync {
Show 13 methods
// Required methods
fn update<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()>;
fn delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>;
fn search<'a>(
&'a self,
builder: &'a SearchBuilder,
) -> EngineFuture<'a, SearchResult>;
fn paginate<'a>(
&'a self,
builder: &'a SearchBuilder,
page: usize,
per_page: usize,
) -> EngineFuture<'a, SearchResult>;
fn create_index<'a>(
&'a self,
index: &'a str,
settings: Value,
) -> EngineFuture<'a, ()>;
fn delete_index<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()>;
// Provided methods
fn delete_in<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()> { ... }
fn flush<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()> { ... }
fn update_bulk<'a>(
&'a self,
docs: &'a [SearchDocument],
) -> EngineFuture<'a, ()> { ... }
fn delete_bulk<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()> { ... }
fn soft_delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()> { ... }
fn soft_delete_in<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()> { ... }
fn reindex<'a>(&'a self, from: &'a str, to: &'a str) -> EngineFuture<'a, ()> { ... }
}Required Methods§
fn update<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()>
Sourcefn delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>
fn delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>
无索引信息的删除;CollectionEngine 跨索引删除,ElasticsearchEngine 仅作用于
default 索引——需要精确语义请用 Self::delete_in。
fn search<'a>( &'a self, builder: &'a SearchBuilder, ) -> EngineFuture<'a, SearchResult>
fn paginate<'a>( &'a self, builder: &'a SearchBuilder, page: usize, per_page: usize, ) -> EngineFuture<'a, SearchResult>
fn create_index<'a>( &'a self, index: &'a str, settings: Value, ) -> EngineFuture<'a, ()>
fn delete_index<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()>
Provided Methods§
Sourcefn delete_in<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()>
fn delete_in<'a>( &'a self, index: &'a str, ids: &'a [String], ) -> EngineFuture<'a, ()>
仅从指定索引删除文档。
Sourcefn flush<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()>
fn flush<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()>
刷新索引,让已写入的文档对搜索可见。
不是清空索引 —— 要删除索引用 Self::delete_index。默认实现是
no-op(校验索引名后直接返回)。只有两个驱动需要覆写:
ES 走 _refresh,XunSearch 发 CMD_INDEX_COMMIT;其余后端写入即对
查询可见,没有「刷新」这一步。
曾有三个驱动把它接到了清空接口上(Meilisearch delete-all、
Typesense 删集合、Algolia /clear),而 README 的生命周期示例在
update 与 search 之间调用 flush —— 照文档跑一遍就会把索引删空。
Sourcefn update_bulk<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()>
fn update_bulk<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()>
批量写入;默认实现逐条调用 Self::update。
Sourcefn delete_bulk<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()>
fn delete_bulk<'a>( &'a self, index: &'a str, ids: &'a [String], ) -> EngineFuture<'a, ()>
批量删除;默认实现逐条调用 Self::delete_in。
Sourcefn soft_delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>
fn soft_delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>
软删除:给文档打上 __soft_deleted: true 标记,配合
SearchBuilder::with_trashed() / only_trashed() 过滤。
不带索引信息,语义因引擎而异:CollectionEngine / DatabaseEngine
跨所有索引标记匹配 id 的文档;HTTP 后端做不到跨索引,会返回
crate::ScoutError::Unsupported(而不是静默什么都不做)——这些后端请用
Self::soft_delete_in。
Sourcefn soft_delete_in<'a>(
&'a self,
index: &'a str,
ids: &'a [String],
) -> EngineFuture<'a, ()>
fn soft_delete_in<'a>( &'a self, index: &'a str, ids: &'a [String], ) -> EngineFuture<'a, ()>
仅对指定索引做软删除;语义与 Self::delete_in 一致。
Sourcefn reindex<'a>(&'a self, from: &'a str, to: &'a str) -> EngineFuture<'a, ()>
fn reindex<'a>(&'a self, from: &'a str, to: &'a str) -> EngineFuture<'a, ()>
重建索引:把 from 索引的内容复制到 to 索引。语义因引擎而异:
CollectionEngine 直接替换 to 索引的既有内容;ElasticsearchEngine 委托
后端 _reindex(合并进 to,发生冲突时整批中止)。
例外:DatabaseEngine 是「移动」而不是「复制」 —— from 会被清空。
它的表里 id 是全局主键(同一 id 不可能同时存在于两个索引),所以复制
在这个 schema 下做不到。需要「from 保留」的语义就别走 database 驱动。
其余引擎(Collection / ES / Algolia)from 保持不变。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".