2021-02-17 01:21:16 +08:00
|
|
|
use serde_json::{Map, Value};
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-03-04 18:23:41 +08:00
|
|
|
use crate::index::{SearchQuery, SearchResult};
|
2020-12-29 18:11:06 +08:00
|
|
|
use super::Data;
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2020-12-29 18:11:06 +08:00
|
|
|
impl Data {
|
2021-02-27 17:19:05 +08:00
|
|
|
pub async fn search<S: AsRef<str>>(
|
2021-02-17 01:21:16 +08:00
|
|
|
&self,
|
2021-02-27 17:19:05 +08:00
|
|
|
index: S,
|
|
|
|
search_query: SearchQuery,
|
2021-02-17 01:21:16 +08:00
|
|
|
) -> anyhow::Result<SearchResult> {
|
2021-02-27 17:19:05 +08:00
|
|
|
self.index_controller.search(index.as_ref().to_string(), search_query).await
|
2020-12-24 19:58:34 +08:00
|
|
|
}
|
2021-02-11 00:08:37 +08:00
|
|
|
|
2021-03-04 21:20:19 +08:00
|
|
|
pub async fn retrieve_documents(
|
2021-02-11 00:08:37 +08:00
|
|
|
&self,
|
2021-03-04 21:20:19 +08:00
|
|
|
index: String,
|
|
|
|
offset: usize,
|
|
|
|
limit: usize,
|
|
|
|
attributes_to_retrieve: Option<Vec<String>>,
|
|
|
|
) -> anyhow::Result<Vec<Map<String, Value>>> {
|
|
|
|
self.index_controller.documents(index, offset, limit, attributes_to_retrieve).await
|
2021-02-11 00:08:37 +08:00
|
|
|
}
|
2021-02-11 17:59:23 +08:00
|
|
|
|
2021-03-04 22:09:00 +08:00
|
|
|
pub async fn retrieve_document(
|
2021-02-11 17:59:23 +08:00
|
|
|
&self,
|
2021-03-04 22:09:00 +08:00
|
|
|
index: impl AsRef<str> + Sync + Send + 'static,
|
|
|
|
document_id: impl AsRef<str> + Sync + Send + 'static,
|
|
|
|
attributes_to_retrieve: Option<Vec<String>>,
|
2021-02-16 06:02:20 +08:00
|
|
|
) -> anyhow::Result<Map<String, Value>>
|
|
|
|
{
|
2021-03-04 22:09:00 +08:00
|
|
|
self.index_controller.document(index.as_ref().to_string(), document_id.as_ref().to_string(), attributes_to_retrieve).await
|
2021-02-11 17:59:23 +08:00
|
|
|
}
|
2020-12-24 19:58:34 +08:00
|
|
|
}
|