From aadbe88048c5eb853d1b7f9bce8f36df76882c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 27 Apr 2023 10:42:48 +0200 Subject: [PATCH] Return an internal error when a field id is missing --- milli/src/search/mod.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 87a46229d..28a53e3a9 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -266,18 +266,24 @@ impl<'a> SearchForFacetValue<'a> { return Err(UserError::InvalidSearchFacet { field: self.facet.clone(), valid_fields: filterable_fields.into_iter().collect(), - })?; + } + .into()); } let fields_ids_map = index.fields_ids_map(rtxn)?; - let (field_id, fst) = match fields_ids_map.id(&self.facet) { - Some(fid) => { - match self.search_query.index.facet_id_string_fst.get(rtxn, &BEU16::new(fid))? { - Some(fst) => (fid, fst), - None => todo!("return an error, is the user trying to search in numbers?"), + let fid = match fields_ids_map.id(&self.facet) { + Some(fid) => fid, + None => { + return Err(FieldIdMapMissingEntry::FieldName { + field_name: self.facet.clone(), + process: "search for facet values", } + .into()); } - None => todo!("return an internal error bug"), + }; + let fst = match self.search_query.index.facet_id_string_fst.get(rtxn, &BEU16::new(fid))? { + Some(fst) => fst, + None => return Ok(vec![]), }; let search_candidates = self.search_query.execute()?.candidates; @@ -296,7 +302,7 @@ impl<'a> SearchForFacetValue<'a> { let mut length = 0; while let Some(facet_value) = stream.next() { let value = std::str::from_utf8(facet_value)?; - let key = FacetGroupKey { field_id, level: 0, left_bound: value }; + let key = FacetGroupKey { field_id: fid, level: 0, left_bound: value }; let docids = match index.facet_id_string_docids.get(rtxn, &key)? { Some(FacetGroupValue { bitmap, .. }) => bitmap, None => todo!("return an internal error"), @@ -319,7 +325,7 @@ impl<'a> SearchForFacetValue<'a> { let mut length = 0; while let Some(facet_value) = stream.next() { let value = std::str::from_utf8(facet_value)?; - let key = FacetGroupKey { field_id, level: 0, left_bound: value }; + let key = FacetGroupKey { field_id: fid, level: 0, left_bound: value }; let docids = match index.facet_id_string_docids.get(rtxn, &key)? { Some(FacetGroupValue { bitmap, .. }) => bitmap, None => todo!("return an internal error"),