From 1ea29bb92e4c7d435ec1c5cba9d5b9150147ad6b Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Thu, 12 Dec 2019 16:37:46 +0100 Subject: [PATCH] Fix unwrap if schema does not contain ranked attributes on a custom ranking setting --- meilisearch-http/src/helpers/meilisearch.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index 6ce77ba91..b5d772157 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -1,6 +1,6 @@ use crate::routes::setting::{RankingOrdering, SettingBody}; use indexmap::IndexMap; -use log::error; +use log::{error, warn}; use meilisearch_core::criterion::*; use meilisearch_core::Highlight; use meilisearch_core::{Index, RankedMap}; @@ -349,13 +349,19 @@ impl<'a> SearchBuilder<'a> { for (rule, order) in ranking_rules.iter() { let custom_ranking = match order { RankingOrdering::Asc => { - SortByAttr::lower_is_better(&ranked_map, &schema, &rule).unwrap() + SortByAttr::lower_is_better(&ranked_map, &schema, &rule) } RankingOrdering::Dsc => { - SortByAttr::higher_is_better(&ranked_map, &schema, &rule).unwrap() + SortByAttr::higher_is_better(&ranked_map, &schema, &rule) } }; - builder.push(custom_ranking); + if let Ok(custom_ranking) = custom_ranking { + builder.push(custom_ranking); + } else { + // TODO push this warning to a log tree + warn!("Custom ranking cannot be added; Attribute {} not registered for ranking", rule) + } + } builder.push(DocumentId); return Ok(Some(builder.build()));