mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Replace the panicking expect by tracked Errors
This commit is contained in:
parent
f0e804afd5
commit
a7d6930905
5 changed files with 109 additions and 66 deletions
|
@ -76,7 +76,7 @@ pub trait Context<'c> {
|
|||
fn word_position_iterator(&self, word: &str, level: TreeLevel, in_prefix_cache: bool, left: Option<u32>, right: Option<u32>) -> heed::Result<Box<dyn Iterator<Item =heed::Result<((&'c str, TreeLevel, u32, u32), RoaringBitmap)>> + 'c>>;
|
||||
fn word_position_last_level(&self, word: &str, in_prefix_cache: bool) -> heed::Result<Option<TreeLevel>>;
|
||||
fn synonyms(&self, word: &str) -> heed::Result<Option<Vec<Vec<String>>>>;
|
||||
fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>>;
|
||||
fn searchable_fields_ids(&self) -> Result<Vec<FieldId>>;
|
||||
fn field_id_word_count_docids(&self, field_id: FieldId, word_count: u8) -> heed::Result<Option<RoaringBitmap>>;
|
||||
fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> heed::Result<Option<RoaringBitmap>>;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ impl<'c> Context<'c> for CriteriaBuilder<'c> {
|
|||
self.index.words_synonyms(self.rtxn, &[word])
|
||||
}
|
||||
|
||||
fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>> {
|
||||
fn searchable_fields_ids(&self) -> Result<Vec<FieldId>> {
|
||||
match self.index.searchable_fields_ids(self.rtxn)? {
|
||||
Some(searchable_fields_ids) => Ok(searchable_fields_ids),
|
||||
None => Ok(self.index.fields_ids_map(self.rtxn)?.ids().collect()),
|
||||
|
@ -478,7 +478,7 @@ pub mod test {
|
|||
todo!()
|
||||
}
|
||||
|
||||
fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>> {
|
||||
fn searchable_fields_ids(&self) -> Result<Vec<FieldId>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,11 @@ use std::mem::size_of;
|
|||
use heed::types::ByteSlice;
|
||||
use roaring::RoaringBitmap;
|
||||
|
||||
use super::{Distinct, DocIter};
|
||||
use crate::error::InternalError;
|
||||
use crate::heed_codec::facet::*;
|
||||
use crate::index::db_name;
|
||||
use crate::{DocumentId, FieldId, Index, Result};
|
||||
use super::{Distinct, DocIter};
|
||||
|
||||
const FID_SIZE: usize = size_of::<FieldId>();
|
||||
const DOCID_SIZE: usize = size_of::<DocumentId>();
|
||||
|
@ -64,7 +66,10 @@ impl<'a> FacetDistinctIter<'a> {
|
|||
let ((_, _, value), _) = item?;
|
||||
let facet_docids = self
|
||||
.facet_string_docids(value)?
|
||||
.expect("Corrupted data: Facet values must exist");
|
||||
.ok_or(InternalError::DatabaseMissingEntry {
|
||||
db_name: db_name::FACET_ID_STRING_DOCIDS,
|
||||
key: None,
|
||||
})?;
|
||||
self.excluded.union_with(&facet_docids);
|
||||
}
|
||||
|
||||
|
@ -80,7 +85,10 @@ impl<'a> FacetDistinctIter<'a> {
|
|||
let ((_, _, value), _) = item?;
|
||||
let facet_docids = self
|
||||
.facet_number_docids(value)?
|
||||
.expect("Corrupted data: Facet values must exist");
|
||||
.ok_or(InternalError::DatabaseMissingEntry {
|
||||
db_name: db_name::FACET_ID_F64_DOCIDS,
|
||||
key: None,
|
||||
})?;
|
||||
self.excluded.union_with(&facet_docids);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
|
|||
use once_cell::sync::Lazy;
|
||||
use roaring::bitmap::RoaringBitmap;
|
||||
|
||||
use distinct::{Distinct, DocIter, FacetDistinct, NoopDistinct};
|
||||
use crate::error::FieldIdMapMissingEntry;
|
||||
use crate::search::criteria::r#final::{Final, FinalResult};
|
||||
use crate::{Index, DocumentId, Result};
|
||||
|
||||
|
@ -22,6 +22,8 @@ pub use self::matching_words::MatchingWords;
|
|||
pub(crate) use self::facet::ParserRule;
|
||||
use self::query_tree::QueryTreeBuilder;
|
||||
|
||||
use distinct::{Distinct, DocIter, FacetDistinct, NoopDistinct};
|
||||
|
||||
// Building these factories is not free.
|
||||
static LEVDIST0: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(0, true));
|
||||
static LEVDIST1: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(1, true));
|
||||
|
@ -142,7 +144,10 @@ impl<'a> Search<'a> {
|
|||
None => self.perform_sort(NoopDistinct, matching_words, criteria),
|
||||
Some(name) => {
|
||||
let field_ids_map = self.index.fields_ids_map(self.rtxn)?;
|
||||
let id = field_ids_map.id(name).expect("distinct not present in field map");
|
||||
let id = field_ids_map.id(name).ok_or_else(|| FieldIdMapMissingEntry::FieldName {
|
||||
field_name: name.to_string(),
|
||||
process: "fetching distint attribute",
|
||||
})?;
|
||||
let distinct = FacetDistinct::new(id, self.index, self.rtxn);
|
||||
self.perform_sort(distinct, matching_words, criteria)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue