diff --git a/Cargo.lock b/Cargo.lock index e1b3b0762..0ba4c97ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1726,7 +1726,7 @@ dependencies = [ [[package]] name = "milli" version = "0.1.0" -source = "git+https://github.com/meilisearch/milli.git?rev=794fce7#794fce7bff3e3461a7f3954fd97f58f8232e5a8e" +source = "git+https://github.com/meilisearch/milli.git?rev=f190d5f#f190d5f496cc39517b6a81300c6dee9b6dba7a38" dependencies = [ "anyhow", "bstr", @@ -1757,6 +1757,7 @@ dependencies = [ "roaring", "serde", "serde_json", + "slice-group-by", "smallstr", "smallvec", "tempfile", diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 2fe9d92d7..58faaebd1 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -38,7 +38,7 @@ main_error = "0.1.0" meilisearch-error = { path = "../meilisearch-error" } meilisearch-tokenizer = { git = "https://github.com/meilisearch/Tokenizer.git", branch = "main" } memmap = "0.7.0" -milli = { git = "https://github.com/meilisearch/milli.git", rev = "794fce7" } +milli = { git = "https://github.com/meilisearch/milli.git", rev = "f190d5f" } mime = "0.3.16" once_cell = "1.5.2" rand = "0.7.3" diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index fee29561a..23adafa16 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -107,11 +107,17 @@ impl Data { .map(|(k, v)| (k, v.to_string())) .collect(); + let criteria = index + .criteria(&txn)? + .into_iter() + .map(|v| v.to_string()) + .collect(); + Ok(Settings { displayed_attributes: Some(Some(displayed_attributes)), searchable_attributes: Some(Some(searchable_attributes)), faceted_attributes: Some(Some(faceted_attributes)), - criteria: None, + ranking_rules: Some(Some(criteria)), }) } diff --git a/meilisearch-http/src/data/search.rs b/meilisearch-http/src/data/search.rs index f26730fcf..7692417ed 100644 --- a/meilisearch-http/src/data/search.rs +++ b/meilisearch-http/src/data/search.rs @@ -6,7 +6,7 @@ use anyhow::{bail, Context}; use either::Either; use heed::RoTxn; use meilisearch_tokenizer::{Analyzer, AnalyzerConfig}; -use milli::{obkv_to_json, FacetCondition, Index, facet::FacetValue}; +use milli::{FacetCondition, Index, MatchingWords, facet::FacetValue, obkv_to_json}; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; @@ -60,7 +60,7 @@ impl SearchQuery { let milli::SearchResult { documents_ids, - found_words, + matching_words, candidates, } = search.execute()?; @@ -91,7 +91,7 @@ impl SearchQuery { for (_id, obkv) in index.documents(&rtxn, documents_ids)? { let mut object = obkv_to_json(&displayed_fields_ids, &fields_ids_map, obkv)?; if let Some(ref attributes_to_highlight) = self.attributes_to_highlight { - highlighter.highlight_record(&mut object, &found_words, attributes_to_highlight); + highlighter.highlight_record(&mut object, &matching_words, attributes_to_highlight); } documents.push(object); } @@ -144,7 +144,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> { Self { analyzer } } - fn highlight_value(&self, value: Value, words_to_highlight: &HashSet) -> Value { + fn highlight_value(&self, value: Value, words_to_highlight: &MatchingWords) -> Value { match value { Value::Null => Value::Null, Value::Bool(boolean) => Value::Bool(boolean), @@ -154,7 +154,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> { let analyzed = self.analyzer.analyze(&old_string); for (word, token) in analyzed.reconstruct() { if token.is_word() { - let to_highlight = words_to_highlight.contains(token.text()); + let to_highlight = words_to_highlight.matches(token.text()); if to_highlight { string.push_str("") } @@ -186,7 +186,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> { fn highlight_record( &self, object: &mut Map, - words_to_highlight: &HashSet, + words_to_highlight: &MatchingWords, attributes_to_highlight: &HashSet, ) { // TODO do we need to create a string for element that are not and needs to be highlight? diff --git a/meilisearch-http/src/index_controller/local_index_controller/update_handler.rs b/meilisearch-http/src/index_controller/local_index_controller/update_handler.rs index 5781a2806..ab2e75206 100644 --- a/meilisearch-http/src/index_controller/local_index_controller/update_handler.rs +++ b/meilisearch-http/src/index_controller/local_index_controller/update_handler.rs @@ -153,7 +153,7 @@ impl UpdateHandler { } // We transpose the settings JSON struct into a real setting update. - if let Some(ref criteria) = settings.criteria { + if let Some(ref criteria) = settings.ranking_rules { match criteria { Some(criteria) => builder.set_criteria(criteria.clone()), None => builder.reset_criteria(), diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index 2d23ebadf..a70d21375 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -83,7 +83,7 @@ pub struct Settings { deserialize_with = "deserialize_some", skip_serializing_if = "Option::is_none", )] - pub criteria: Option>>, + pub ranking_rules: Option>>, } impl Settings { @@ -92,7 +92,7 @@ impl Settings { displayed_attributes: Some(None), searchable_attributes: Some(None), faceted_attributes: Some(None), - criteria: Some(None), + ranking_rules: Some(None), } } } diff --git a/meilisearch-http/src/routes/settings/mod.rs b/meilisearch-http/src/routes/settings/mod.rs index b65729b31..5786ee2d4 100644 --- a/meilisearch-http/src/routes/settings/mod.rs +++ b/meilisearch-http/src/routes/settings/mod.rs @@ -103,11 +103,11 @@ make_setting_route!( //distinct_attribute //); -//make_setting_route!( - //"/indexes/{index_uid}/settings/ranking-rules", - //Vec, - //ranking_rules -//); +make_setting_route!( + "/indexes/{index_uid}/settings/ranking-rules", + Vec, + ranking_rules +); macro_rules! create_services { ($($mod:ident),*) => { @@ -128,7 +128,8 @@ macro_rules! create_services { create_services!( faceted_attributes, displayed_attributes, - searchable_attributes + searchable_attributes, + ranking_rules ); #[post("/indexes/{index_uid}/settings", wrap = "Authentication::Private")] diff --git a/meilisearch-http/tests/settings/get_settings.rs b/meilisearch-http/tests/settings/get_settings.rs index d57c860b0..e5fbbde35 100644 --- a/meilisearch-http/tests/settings/get_settings.rs +++ b/meilisearch-http/tests/settings/get_settings.rs @@ -16,10 +16,11 @@ async fn get_settings() { let (response, code) = index.settings().await; assert_eq!(code, 200); let settings = response.as_object().unwrap(); - assert_eq!(settings.keys().len(), 3); + assert_eq!(settings.keys().len(), 4); assert_eq!(settings["displayedAttributes"], json!(["*"])); assert_eq!(settings["searchableAttributes"], json!(["*"])); assert_eq!(settings["facetedAttributes"], json!({})); + assert_eq!(settings["rankingRules"], json!(["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"])); } #[actix_rt::test]