mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Expose an http route for the WordsPrefixes update
This commit is contained in:
parent
c318373b88
commit
c62d2f56d8
@ -225,6 +225,7 @@ enum UpdateMeta {
|
|||||||
ClearDocuments,
|
ClearDocuments,
|
||||||
Settings(Settings),
|
Settings(Settings),
|
||||||
Facets(Facets),
|
Facets(Facets),
|
||||||
|
WordsPrefixes(WordsPrefixes),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -275,6 +276,14 @@ struct Facets {
|
|||||||
min_level_size: Option<NonZeroUsize>,
|
min_level_size: Option<NonZeroUsize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct WordsPrefixes {
|
||||||
|
threshold: Option<f64>,
|
||||||
|
max_prefix_length: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
// Any value that is present is considered Some value, including null.
|
// Any value that is present is considered Some value, including null.
|
||||||
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
|
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
|
||||||
where T: Deserialize<'de>,
|
where T: Deserialize<'de>,
|
||||||
@ -467,6 +476,21 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
Ok(()) => wtxn.commit().map_err(Into::into),
|
Ok(()) => wtxn.commit().map_err(Into::into),
|
||||||
Err(e) => Err(e.into())
|
Err(e) => Err(e.into())
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
UpdateMeta::WordsPrefixes(settings) => {
|
||||||
|
// We must use the write transaction of the update here.
|
||||||
|
let mut wtxn = index_cloned.write_txn()?;
|
||||||
|
let mut builder = update_builder.words_prefixes(&mut wtxn, &index_cloned);
|
||||||
|
if let Some(value) = settings.threshold {
|
||||||
|
builder.threshold(value);
|
||||||
|
}
|
||||||
|
if let Some(value) = settings.max_prefix_length {
|
||||||
|
builder.max_prefix_length(value);
|
||||||
|
}
|
||||||
|
match builder.execute() {
|
||||||
|
Ok(()) => wtxn.commit().map_err(Into::into),
|
||||||
|
Err(e) => Err(e.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -884,6 +908,19 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
warp::reply()
|
warp::reply()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let update_store_cloned = update_store.clone();
|
||||||
|
let update_status_sender_cloned = update_status_sender.clone();
|
||||||
|
let change_words_prefixes_route = warp::filters::method::post()
|
||||||
|
.and(warp::path!("words-prefixes"))
|
||||||
|
.and(warp::body::json())
|
||||||
|
.map(move |settings: WordsPrefixes| {
|
||||||
|
let meta = UpdateMeta::WordsPrefixes(settings);
|
||||||
|
let update_id = update_store_cloned.register_update(&meta, &[]).unwrap();
|
||||||
|
let _ = update_status_sender_cloned.send(UpdateStatus::Pending { update_id, meta });
|
||||||
|
eprintln!("update {} registered", update_id);
|
||||||
|
warp::reply()
|
||||||
|
});
|
||||||
|
|
||||||
let update_store_cloned = update_store.clone();
|
let update_store_cloned = update_store.clone();
|
||||||
let update_status_sender_cloned = update_status_sender.clone();
|
let update_status_sender_cloned = update_status_sender.clone();
|
||||||
let abort_update_id_route = warp::filters::method::delete()
|
let abort_update_id_route = warp::filters::method::delete()
|
||||||
@ -958,6 +995,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.or(clearing_route)
|
.or(clearing_route)
|
||||||
.or(change_settings_route)
|
.or(change_settings_route)
|
||||||
.or(change_facet_levels_route)
|
.or(change_facet_levels_route)
|
||||||
|
.or(change_words_prefixes_route)
|
||||||
.or(update_ws_route);
|
.or(update_ws_route);
|
||||||
|
|
||||||
let addr = SocketAddr::from_str(&opt.http_listen_addr)?;
|
let addr = SocketAddr::from_str(&opt.http_listen_addr)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user