meilisearch/meilisearch-http/src/data/search.rs

39 lines
1011 B
Rust
Raw Normal View History

2021-02-17 01:21:16 +08:00
use serde_json::{Map, Value};
2020-12-12 20:32:06 +08:00
2020-12-29 18:11:06 +08:00
use super::Data;
2021-03-16 01:11:10 +08:00
use crate::index::{SearchQuery, SearchResult};
use crate::index_controller::error::Result;
2020-12-12 20:32:06 +08:00
2020-12-29 18:11:06 +08:00
impl Data {
2021-03-15 23:52:05 +08:00
pub async fn search(
2021-02-17 01:21:16 +08:00
&self,
2021-03-15 23:52:05 +08:00
index: String,
search_query: SearchQuery,
) -> Result<SearchResult> {
2021-03-15 23:52:05 +08:00
self.index_controller.search(index, 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>>,
) -> Result<Vec<Map<String, Value>>> {
2021-03-16 01:11:10 +08:00
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-15 23:52:05 +08:00
index: String,
document_id: String,
2021-03-04 22:09:00 +08:00
attributes_to_retrieve: Option<Vec<String>>,
) -> Result<Map<String, Value>> {
2021-03-16 01:11:10 +08:00
self.index_controller
.document(index, document_id, attributes_to_retrieve)
.await
2021-02-11 17:59:23 +08:00
}
2020-12-24 19:58:34 +08:00
}