2021-03-15 18:11:10 +01:00
|
|
|
use milli::update::{IndexDocumentsMethod, UpdateFormat};
|
2020-12-29 11:11:06 +01:00
|
|
|
|
2021-06-23 14:56:02 +02:00
|
|
|
use crate::extractors::payload::Payload;
|
2021-05-10 17:30:09 +02:00
|
|
|
use crate::index::{Checked, Settings};
|
2021-06-15 17:39:07 +02:00
|
|
|
use crate::index_controller::{error::Result, IndexMetadata, IndexSettings, UpdateStatus};
|
2021-06-23 14:56:02 +02:00
|
|
|
use crate::Data;
|
2021-03-04 11:56:32 +01:00
|
|
|
|
2020-12-29 11:11:06 +01:00
|
|
|
impl Data {
|
2021-02-26 17:14:11 +01:00
|
|
|
pub async fn add_documents(
|
2020-12-29 11:11:06 +01:00
|
|
|
&self,
|
2021-03-15 16:52:05 +01:00
|
|
|
index: String,
|
2020-12-29 11:11:06 +01:00
|
|
|
method: IndexDocumentsMethod,
|
|
|
|
format: UpdateFormat,
|
2021-03-03 10:57:13 +01:00
|
|
|
stream: Payload,
|
2021-02-13 12:22:59 +01:00
|
|
|
primary_key: Option<String>,
|
2021-06-14 21:26:35 +02:00
|
|
|
) -> Result<UpdateStatus> {
|
2021-03-15 18:11:10 +01:00
|
|
|
let update_status = self
|
|
|
|
.index_controller
|
|
|
|
.add_documents(index, method, format, stream, primary_key)
|
|
|
|
.await?;
|
2021-02-26 09:10:04 +01:00
|
|
|
Ok(update_status)
|
2020-12-29 11:11:06 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 19:51:47 +01:00
|
|
|
pub async fn update_settings(
|
2021-01-01 16:59:49 +01:00
|
|
|
&self,
|
2021-03-04 12:20:14 +01:00
|
|
|
index: String,
|
2021-05-10 17:30:09 +02:00
|
|
|
settings: Settings<Checked>,
|
2021-03-11 22:33:31 +01:00
|
|
|
create: bool,
|
2021-06-14 21:26:35 +02:00
|
|
|
) -> Result<UpdateStatus> {
|
2021-03-15 18:11:10 +01:00
|
|
|
let update = self
|
|
|
|
.index_controller
|
|
|
|
.update_settings(index, settings, create)
|
|
|
|
.await?;
|
2021-03-15 16:52:05 +01:00
|
|
|
Ok(update)
|
2021-01-01 16:59:49 +01:00
|
|
|
}
|
2020-12-29 11:11:06 +01:00
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
pub async fn clear_documents(&self, index: String) -> Result<UpdateStatus> {
|
2021-03-15 16:52:05 +01:00
|
|
|
let update = self.index_controller.clear_documents(index).await?;
|
2021-03-04 16:04:12 +01:00
|
|
|
Ok(update)
|
2021-02-11 12:03:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 17:39:14 +01:00
|
|
|
pub async fn delete_documents(
|
|
|
|
&self,
|
2021-03-15 16:52:05 +01:00
|
|
|
index: String,
|
2021-03-04 15:59:18 +01:00
|
|
|
document_ids: Vec<String>,
|
2021-06-14 21:26:35 +02:00
|
|
|
) -> Result<UpdateStatus> {
|
2021-03-15 18:11:10 +01:00
|
|
|
let update = self
|
|
|
|
.index_controller
|
|
|
|
.delete_documents(index, document_ids)
|
|
|
|
.await?;
|
2021-03-15 16:52:05 +01:00
|
|
|
Ok(update)
|
2021-02-12 17:39:14 +01:00
|
|
|
}
|
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
pub async fn delete_index(&self, index: String) -> Result<()> {
|
2021-03-15 16:52:05 +01:00
|
|
|
self.index_controller.delete_index(index).await?;
|
2021-03-06 12:57:56 +01:00
|
|
|
Ok(())
|
2021-02-15 10:53:21 +01:00
|
|
|
}
|
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
pub async fn get_update_status(&self, index: String, uid: u64) -> Result<UpdateStatus> {
|
2021-03-15 16:52:05 +01:00
|
|
|
self.index_controller.update_status(index, uid).await
|
2021-01-28 17:20:51 +01:00
|
|
|
}
|
2020-12-30 19:17:13 +01:00
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
pub async fn get_updates_status(&self, index: String) -> Result<Vec<UpdateStatus>> {
|
2021-03-15 16:52:05 +01:00
|
|
|
self.index_controller.all_update_status(index).await
|
2021-01-28 18:32:24 +01:00
|
|
|
}
|
2021-02-09 11:26:52 +01:00
|
|
|
|
2021-03-12 14:48:43 +01:00
|
|
|
pub async fn update_index(
|
2021-02-09 11:26:52 +01:00
|
|
|
&self,
|
2021-03-15 16:52:05 +01:00
|
|
|
uid: String,
|
|
|
|
primary_key: Option<String>,
|
2021-03-15 18:11:10 +01:00
|
|
|
new_uid: Option<String>,
|
2021-06-14 21:26:35 +02:00
|
|
|
) -> Result<IndexMetadata> {
|
2021-03-12 14:48:43 +01:00
|
|
|
let settings = IndexSettings {
|
2021-03-15 16:52:05 +01:00
|
|
|
uid: new_uid,
|
|
|
|
primary_key,
|
2021-03-12 14:48:43 +01:00
|
|
|
};
|
2021-02-09 11:26:52 +01:00
|
|
|
|
2021-03-15 16:52:05 +01:00
|
|
|
self.index_controller.update_index(uid, settings).await
|
2021-02-09 11:26:52 +01:00
|
|
|
}
|
2020-12-29 11:11:06 +01:00
|
|
|
}
|