1use std::future::Future;
2use std::pin::Pin;
3
4use crate::{Result, SearchBuilder, SearchDocument, SearchResult};
5
6pub type EngineFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T>> + Send + 'a>>;
7
8pub trait Engine: Send + Sync {
9 fn update<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()>;
10 fn delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()>;
13 fn delete_in<'a>(&'a self, index: &'a str, ids: &'a [String]) -> EngineFuture<'a, ()> {
15 let _ = (index, ids);
16 Box::pin(async move {
17 Err(crate::ScoutError::Unsupported(
18 "delete_in not implemented by this engine".to_string(),
19 ))
20 })
21 }
22 fn search<'a>(&'a self, builder: &'a SearchBuilder) -> EngineFuture<'a, SearchResult>;
23 fn paginate<'a>(
24 &'a self,
25 builder: &'a SearchBuilder,
26 page: usize,
27 per_page: usize,
28 ) -> EngineFuture<'a, SearchResult>;
29 fn flush<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()> {
40 Box::pin(async move {
41 crate::validate_index_name(index)?;
42 Ok(())
43 })
44 }
45 fn create_index<'a>(
46 &'a self,
47 index: &'a str,
48 settings: serde_json::Value,
49 ) -> EngineFuture<'a, ()>;
50 fn delete_index<'a>(&'a self, index: &'a str) -> EngineFuture<'a, ()>;
51 fn update_bulk<'a>(&'a self, docs: &'a [SearchDocument]) -> EngineFuture<'a, ()> {
53 Box::pin(async move {
54 for doc in docs {
55 self.update(std::slice::from_ref(doc)).await?;
56 }
57 Ok(())
58 })
59 }
60 fn delete_bulk<'a>(&'a self, index: &'a str, ids: &'a [String]) -> EngineFuture<'a, ()> {
62 Box::pin(async move {
63 for id in ids {
64 self.delete_in(index, std::slice::from_ref(id)).await?;
65 }
66 Ok(())
67 })
68 }
69 fn soft_delete<'a>(&'a self, ids: &'a [String]) -> EngineFuture<'a, ()> {
77 let _ = ids;
78 Box::pin(async move {
79 Err(crate::ScoutError::Unsupported(
80 "soft_delete (index-less) is not supported by this engine; \
81 use soft_delete_in(index, ids) instead"
82 .to_string(),
83 ))
84 })
85 }
86 fn soft_delete_in<'a>(&'a self, index: &'a str, ids: &'a [String]) -> EngineFuture<'a, ()> {
88 let _ = (index, ids);
89 Box::pin(async move {
90 Err(crate::ScoutError::Unsupported(
91 "soft_delete_in not implemented by this engine".to_string(),
92 ))
93 })
94 }
95 fn reindex<'a>(&'a self, from: &'a str, to: &'a str) -> EngineFuture<'a, ()> {
104 let _ = (from, to);
105 Box::pin(async move {
106 Err(crate::ScoutError::Unsupported(
107 "reindex not implemented by this engine".to_string(),
108 ))
109 })
110 }
111}