From 65ca80bdde170fba76a2d3175b1580ec0654c3cb Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 5 Mar 2021 19:31:49 +0100 Subject: [PATCH 1/4] enable criterion setting --- meilisearch-http/src/data/mod.rs | 8 +++++++- .../local_index_controller/update_handler.rs | 2 +- meilisearch-http/src/index_controller/mod.rs | 4 ++-- meilisearch-http/src/routes/settings/mod.rs | 13 +++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index ed5ce4952..15db0e4ae 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -106,11 +106,17 @@ impl Data { .map(|(k, v)| (k, v.to_string())) .collect(); + let criteria = index + .criteria(&txn)? + .into_iter() + .map(|v| format!("{:?}", v)) + .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/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 b20e43749..fc8efa036 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 00bc4220e..bf6d92133 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")] From f4f42ec4411e954393b5b756deffea096ae516d1 Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 5 Mar 2021 20:06:10 +0100 Subject: [PATCH 2/4] add tests --- meilisearch-http/src/data/search.rs | 1 + meilisearch-http/tests/settings/get_settings.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/meilisearch-http/src/data/search.rs b/meilisearch-http/src/data/search.rs index f26730fcf..c76e21638 100644 --- a/meilisearch-http/src/data/search.rs +++ b/meilisearch-http/src/data/search.rs @@ -62,6 +62,7 @@ impl SearchQuery { documents_ids, found_words, candidates, + .. } = search.execute()?; let mut documents = Vec::new(); diff --git a/meilisearch-http/tests/settings/get_settings.rs b/meilisearch-http/tests/settings/get_settings.rs index bae044acb..6c57863ac 100644 --- a/meilisearch-http/tests/settings/get_settings.rs +++ b/meilisearch-http/tests/settings/get_settings.rs @@ -8,7 +8,9 @@ async fn get_settings_unexisting_index() { assert_eq!(code, 400) } +// test broken, should be fixed with milli#101 #[actix_rt::test] +#[ignore] async fn get_settings() { let server = Server::new().await; let index = server.index("test"); @@ -16,10 +18,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", "proximmity", "attributes", "wordsPosition", "exactness"])); } #[actix_rt::test] From 944a5bb36e1cecc34af95c2d951d5c4bc181452a Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 8 Mar 2021 13:28:31 +0100 Subject: [PATCH 3/4] update milli --- Cargo.lock | 3 ++- meilisearch-http/Cargo.toml | 2 +- meilisearch-http/src/data/mod.rs | 2 +- meilisearch-http/src/data/search.rs | 12 ++++++------ meilisearch-http/tests/settings/get_settings.rs | 3 +-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17575cd48..c54acfa02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1725,7 +1725,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", @@ -1756,6 +1756,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 b760a3d27..8ee612d3f 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 15db0e4ae..2904bb67f 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -109,7 +109,7 @@ impl Data { let criteria = index .criteria(&txn)? .into_iter() - .map(|v| format!("{:?}", v)) + .map(|v| format!("{}", v)) .collect(); Ok(Settings { diff --git a/meilisearch-http/src/data/search.rs b/meilisearch-http/src/data/search.rs index c76e21638..a721a8200 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()?; @@ -92,7 +92,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); } @@ -145,7 +145,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), @@ -155,7 +155,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("") } @@ -187,7 +187,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/tests/settings/get_settings.rs b/meilisearch-http/tests/settings/get_settings.rs index 6c57863ac..25d46b961 100644 --- a/meilisearch-http/tests/settings/get_settings.rs +++ b/meilisearch-http/tests/settings/get_settings.rs @@ -10,7 +10,6 @@ async fn get_settings_unexisting_index() { // test broken, should be fixed with milli#101 #[actix_rt::test] -#[ignore] async fn get_settings() { let server = Server::new().await; let index = server.index("test"); @@ -22,7 +21,7 @@ async fn get_settings() { assert_eq!(settings["displayedAttributes"], json!(["*"])); assert_eq!(settings["searchableAttributes"], json!(["*"])); assert_eq!(settings["facetedAttributes"], json!({})); - assert_eq!(settings["rankingRules"], json!(["typo", "words", "proximmity", "attributes", "wordsPosition", "exactness"])); + assert_eq!(settings["rankingRules"], json!(["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"])); } #[actix_rt::test] From e9b90d5380be9a89a31637898bd15d5fb33f102d Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 8 Mar 2021 13:51:33 +0100 Subject: [PATCH 4/4] fixes from review --- meilisearch-http/src/data/mod.rs | 2 +- meilisearch-http/src/data/search.rs | 1 - meilisearch-http/tests/settings/get_settings.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index 2904bb67f..05a29381a 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -109,7 +109,7 @@ impl Data { let criteria = index .criteria(&txn)? .into_iter() - .map(|v| format!("{}", v)) + .map(|v| v.to_string()) .collect(); Ok(Settings { diff --git a/meilisearch-http/src/data/search.rs b/meilisearch-http/src/data/search.rs index a721a8200..7692417ed 100644 --- a/meilisearch-http/src/data/search.rs +++ b/meilisearch-http/src/data/search.rs @@ -62,7 +62,6 @@ impl SearchQuery { documents_ids, matching_words, candidates, - .. } = search.execute()?; let mut documents = Vec::new(); diff --git a/meilisearch-http/tests/settings/get_settings.rs b/meilisearch-http/tests/settings/get_settings.rs index 25d46b961..d1ce6ea5d 100644 --- a/meilisearch-http/tests/settings/get_settings.rs +++ b/meilisearch-http/tests/settings/get_settings.rs @@ -8,7 +8,6 @@ async fn get_settings_unexisting_index() { assert_eq!(code, 400) } -// test broken, should be fixed with milli#101 #[actix_rt::test] async fn get_settings() { let server = Server::new().await;