From c7c8ca63b68f0692798a9c8b2f5745945ecc8949 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 7 Jan 2021 12:38:24 +0100 Subject: [PATCH 1/3] fix changelog typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afcf87a61..ac1f6712b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Fix setting consistency bug (#1128) - Fix attributes to retrieve bug (#1131) - Increase default payload size (#1147) - - Improvements to code quality (#1167, #1165, #1126, #1161) + - Improvements to code quality (#1167, #1165, #1126, #1151) ## v0.17.0 - Fix corrupted data during placeholder search (#1089) From a95a18afe4a9e766ac43315af6102f3cc17a1a98 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 3 Feb 2021 11:59:29 +0100 Subject: [PATCH 2/3] ignore primary key if it is already set --- meilisearch-http/src/routes/document.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index 943351bd7..202575cc3 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -175,7 +175,6 @@ async fn update_multiple_documents( .ok_or(meilisearch_core::Error::SchemaMissing)?; match (params.into_inner().primary_key, schema.primary_key()) { - (Some(_), Some(_)) => return Err(meilisearch_schema::Error::PrimaryKeyAlreadyPresent)?, (Some(key), None) => document_addition.set_primary_key(key), (None, None) => { let key = body @@ -184,7 +183,7 @@ async fn update_multiple_documents( .ok_or(meilisearch_core::Error::MissingPrimaryKey)?; document_addition.set_primary_key(key); } - (None, Some(_)) => () + _ => () } for document in body.into_inner() { From 1df0fdf3e2d910433d795db5f606fe906dbf3bcb Mon Sep 17 00:00:00 2001 From: many Date: Wed, 3 Feb 2021 15:05:15 +0100 Subject: [PATCH 3/3] fix synonyms normalization Synonyms needs to be indexed in ascendant order, and the new normalization step for synonyms potentially changes this order which break the indexation process because "Harry Potter" > "HP" but "harry potter" < "hp" --- meilisearch-core/src/update/settings_update.rs | 15 +++++++++++---- meilisearch-http/tests/settings.rs | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index e96d5702c..c9d40fa1b 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, collections::{BTreeMap, BTreeSet}}; use heed::Result as ZResult; -use fst::{set::OpBuilder, SetBuilder}; +use fst::{SetBuilder, set::OpBuilder}; use sdset::SetBuf; use meilisearch_schema::Schema; use meilisearch_tokenizer::analyzer::{Analyzer, AnalyzerConfig}; @@ -298,16 +298,23 @@ pub fn apply_synonyms_update( .tokens() .fold(String::new(), |s, t| s + t.text()) } + + // normalize synonyms and reorder them creating a BTreeMap + let synonyms: BTreeMap> = synonyms.into_iter().map( |(word, alternatives)| { + let word = normalize(&analyzer, &word); + let alternatives = alternatives.into_iter().map(|text| normalize(&analyzer, &text)).collect(); + (word, alternatives) + }).collect(); + + // index synonyms, + // synyonyms have to be ordered by key before indexation let mut synonyms_builder = SetBuilder::memory(); synonyms_store.clear(writer)?; for (word, alternatives) in synonyms { - let word = normalize(&analyzer, &word); - synonyms_builder.insert(&word)?; let alternatives = { - let alternatives = alternatives.iter().map(|text| normalize(&analyzer, &text)).collect(); let alternatives = SetBuf::from_dirty(alternatives); let mut alternatives_builder = SetBuilder::memory(); alternatives_builder.extend_iter(alternatives)?; diff --git a/meilisearch-http/tests/settings.rs b/meilisearch-http/tests/settings.rs index 6b125c13a..98973b56f 100644 --- a/meilisearch-http/tests/settings.rs +++ b/meilisearch-http/tests/settings.rs @@ -171,6 +171,8 @@ async fn write_all_and_update() { "synonyms": { "road": ["street", "avenue"], "street": ["avenue"], + "HP": ["Harry Potter"], + "Harry Potter": ["HP"] }, "attributesForFaceting": ["title"], }); @@ -208,6 +210,8 @@ async fn write_all_and_update() { "synonyms": { "road": ["street", "avenue"], "street": ["avenue"], + "hp": ["harry potter"], + "harry potter": ["hp"] }, "attributesForFaceting": ["title"], });