Update the HTTP settings route to accept the faceted fields

This commit is contained in:
Clément Renault 2020-11-13 16:16:07 +01:00
parent 8e6efe4d87
commit 23f9a22edc
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 21 additions and 1 deletions

10
http-ui/Cargo.lock generated
View File

@ -989,6 +989,7 @@ dependencies = [
"near-proximity", "near-proximity",
"obkv", "obkv",
"once_cell", "once_cell",
"ordered-float",
"rayon", "rayon",
"ringtail", "ringtail",
"roaring", "roaring",
@ -1205,6 +1206,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "ordered-float"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fe9037165d7023b1228bc4ae9a2fa1a2b0095eca6c2998c624723dfd01314a5"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "page_size" name = "page_size"
version = "0.4.2" version = "0.4.2"

View File

@ -1,5 +1,5 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashSet; use std::collections::{HashMap, HashSet};
use std::fs::{File, create_dir_all}; use std::fs::{File, create_dir_all};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::PathBuf; use std::path::PathBuf;
@ -210,6 +210,8 @@ enum UpdateMetaProgress {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Settings { struct Settings {
#[serde( #[serde(
default, default,
@ -224,6 +226,9 @@ struct Settings {
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
)] )]
searchable_attributes: Option<Option<Vec<String>>>, searchable_attributes: Option<Option<Vec<String>>>,
#[serde(default)]
faceted_attributes: Option<HashMap<String, String>>,
} }
// Any value that is present is considered Some value, including null. // Any value that is present is considered Some value, including null.
@ -367,6 +372,11 @@ async fn main() -> anyhow::Result<()> {
} }
} }
// We transpose the settings JSON struct into a real setting update.
if let Some(facet_types) = settings.faceted_attributes {
builder.set_faceted_fields(facet_types);
}
let result = builder.execute(|indexing_step| { let result = builder.execute(|indexing_step| {
let (current, total) = match indexing_step { let (current, total) = match indexing_step {
TransformFromUserIntoGenericFormat { documents_seen } => (documents_seen, None), TransformFromUserIntoGenericFormat { documents_seen } => (documents_seen, None),