mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 08:48:32 +08:00
Expose a route in the http-ui to update the WordsLevelPositions
This commit is contained in:
parent
3a25137ee4
commit
e8cc7f9cee
@ -229,6 +229,7 @@ enum UpdateMeta {
|
||||
Settings(Settings),
|
||||
Facets(Facets),
|
||||
WordsPrefixes(WordsPrefixes),
|
||||
WordsLevelPositions(WordsLevelPositions),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -281,6 +282,22 @@ struct WordsPrefixes {
|
||||
max_prefix_length: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WordsLevelPositions {
|
||||
level_group_size: Option<NonZeroUsize>,
|
||||
min_level_size: Option<NonZeroUsize>,
|
||||
}
|
||||
|
||||
// Any value that is present is considered Some value, including null.
|
||||
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
|
||||
where T: Deserialize<'de>,
|
||||
D: Deserializer<'de>
|
||||
{
|
||||
Deserialize::deserialize(deserializer).map(Some)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let opt = Opt::from_args();
|
||||
@ -493,6 +510,21 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(()) => wtxn.commit().map_err(Into::into),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
},
|
||||
UpdateMeta::WordsLevelPositions(levels) => {
|
||||
// We must use the write transaction of the update here.
|
||||
let mut wtxn = index_cloned.write_txn()?;
|
||||
let mut builder = update_builder.words_level_positions(&mut wtxn, &index_cloned);
|
||||
if let Some(value) = levels.level_group_size {
|
||||
builder.level_group_size(value);
|
||||
}
|
||||
if let Some(value) = levels.min_level_size {
|
||||
builder.min_level_size(value);
|
||||
}
|
||||
match builder.execute() {
|
||||
Ok(()) => wtxn.commit().map_err(Into::into),
|
||||
Err(e) => Err(e.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -923,6 +955,19 @@ async fn main() -> anyhow::Result<()> {
|
||||
warp::reply()
|
||||
});
|
||||
|
||||
let update_store_cloned = update_store.clone();
|
||||
let update_status_sender_cloned = update_status_sender.clone();
|
||||
let change_words_level_positions_route = warp::filters::method::post()
|
||||
.and(warp::path!("words-level-positions"))
|
||||
.and(warp::body::json())
|
||||
.map(move |levels: WordsLevelPositions| {
|
||||
let meta = UpdateMeta::WordsLevelPositions(levels);
|
||||
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_status_sender_cloned = update_status_sender.clone();
|
||||
let abort_update_id_route = warp::filters::method::delete()
|
||||
@ -998,6 +1043,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
.or(change_settings_route)
|
||||
.or(change_facet_levels_route)
|
||||
.or(change_words_prefixes_route)
|
||||
.or(change_words_level_positions_route)
|
||||
.or(update_ws_route);
|
||||
|
||||
let addr = SocketAddr::from_str(&opt.http_listen_addr)?;
|
||||
|
Loading…
Reference in New Issue
Block a user