mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
fixes for review
This commit is contained in:
parent
40d7396d90
commit
dc9ca2ebc9
20 changed files with 66 additions and 64 deletions
|
@ -172,7 +172,6 @@ where
|
|||
|
||||
debug!("bucket sort took {:.02?}", before_bucket_sort.elapsed());
|
||||
|
||||
|
||||
Ok(documents)
|
||||
}
|
||||
|
||||
|
|
|
@ -87,12 +87,12 @@ impl fmt::Display for Error {
|
|||
match self {
|
||||
Io(e) => write!(f, "{}", e),
|
||||
IndexAlreadyExists => write!(f, "index already exists"),
|
||||
MissingIdentifier => write!(f, "schema cannot be build without identifier"),
|
||||
MissingIdentifier => write!(f, "schema cannot be built without identifier"),
|
||||
SchemaMissing => write!(f, "this index does not have a schema"),
|
||||
WordIndexMissing => write!(f, "this index does not have a word index"),
|
||||
MissingDocumentId => write!(f, "document id is missing"),
|
||||
MaxFieldsLimitExceeded => write!(f, "maximum field in a document is exceeded"),
|
||||
Schema(e) => write!(f, "schemas error; {}", e),
|
||||
MaxFieldsLimitExceeded => write!(f, "maximum number of fields in a document exceeded"),
|
||||
Schema(e) => write!(f, "schema error; {}", e),
|
||||
Zlmdb(e) => write!(f, "heed error; {}", e),
|
||||
Fst(e) => write!(f, "fst error; {}", e),
|
||||
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
||||
|
|
|
@ -275,7 +275,7 @@ mod tests {
|
|||
let mut final_indexes = Vec::new();
|
||||
for index in indexes {
|
||||
let name = index.attribute.to_string();
|
||||
schema.get_or_create_empty(&name).unwrap();
|
||||
schema.insert(&name).unwrap();
|
||||
let indexed_pos = schema.set_indexed(&name).unwrap().1;
|
||||
let index = DocIndex {
|
||||
attribute: indexed_pos.0,
|
||||
|
|
|
@ -235,7 +235,7 @@ impl<'a, 'b> ser::SerializeMap for MapSerializer<'a, 'b> {
|
|||
let key = key.serialize(ConvertToString)?;
|
||||
serialize_value(
|
||||
self.txn,
|
||||
key,
|
||||
key.as_str(),
|
||||
self.schema,
|
||||
self.document_id,
|
||||
self.document_store,
|
||||
|
@ -275,7 +275,7 @@ impl<'a, 'b> ser::SerializeStruct for StructSerializer<'a, 'b> {
|
|||
{
|
||||
serialize_value(
|
||||
self.txn,
|
||||
key.to_string(),
|
||||
key,
|
||||
self.schema,
|
||||
self.document_id,
|
||||
self.document_store,
|
||||
|
@ -293,7 +293,7 @@ impl<'a, 'b> ser::SerializeStruct for StructSerializer<'a, 'b> {
|
|||
|
||||
pub fn serialize_value<'a, T: ?Sized>(
|
||||
txn: &mut heed::RwTxn<MainT>,
|
||||
attribute: String,
|
||||
attribute: &str,
|
||||
schema: &'a mut Schema,
|
||||
document_id: DocumentId,
|
||||
document_store: DocumentsFields,
|
||||
|
@ -305,7 +305,7 @@ pub fn serialize_value<'a, T: ?Sized>(
|
|||
where
|
||||
T: ser::Serialize,
|
||||
{
|
||||
let field_id = schema.get_or_create(&attribute)?;
|
||||
let field_id = schema.insert_and_index(&attribute)?;
|
||||
serialize_value_with_id(
|
||||
txn,
|
||||
field_id,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||
use std::str::FromStr;
|
||||
use std::iter::IntoIterator;
|
||||
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use once_cell::sync::Lazy;
|
||||
|
@ -17,8 +18,6 @@ pub struct Settings {
|
|||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub ranking_distinct: Option<Option<String>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub identifier: Option<Option<String>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub searchable_attributes: Option<Option<Vec<String>>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub displayed_attributes: Option<Option<HashSet<String>>>,
|
||||
|
@ -43,7 +42,7 @@ impl Settings {
|
|||
let settings = self.clone();
|
||||
|
||||
let ranking_rules = match settings.ranking_rules {
|
||||
Some(Some(rules)) => UpdateState::Update(RankingRule::from_vec(rules.iter().map(|m| m.as_ref()).collect())?),
|
||||
Some(Some(rules)) => UpdateState::Update(RankingRule::from_iter(rules.iter())?),
|
||||
Some(None) => UpdateState::Clear,
|
||||
None => UpdateState::Nothing,
|
||||
};
|
||||
|
@ -51,7 +50,7 @@ impl Settings {
|
|||
Ok(SettingsUpdate {
|
||||
ranking_rules,
|
||||
ranking_distinct: settings.ranking_distinct.into(),
|
||||
identifier: settings.identifier.into(),
|
||||
identifier: UpdateState::Nothing,
|
||||
searchable_attributes: settings.searchable_attributes.into(),
|
||||
displayed_attributes: settings.displayed_attributes.into(),
|
||||
stop_words: settings.stop_words.into(),
|
||||
|
@ -139,16 +138,16 @@ impl FromStr for RankingRule {
|
|||
}
|
||||
|
||||
impl RankingRule {
|
||||
pub fn get_field(&self) -> Option<&str> {
|
||||
pub fn field(&self) -> Option<&str> {
|
||||
match self {
|
||||
RankingRule::Asc(field) | RankingRule::Dsc(field) => Some(field),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_vec(rules: Vec<&str>) -> Result<Vec<RankingRule>, RankingRuleConversionError> {
|
||||
rules.iter()
|
||||
.map(|s| RankingRule::from_str(s))
|
||||
pub fn from_iter(rules: impl IntoIterator<Item = impl AsRef<str>>) -> Result<Vec<RankingRule>, RankingRuleConversionError> {
|
||||
rules.into_iter()
|
||||
.map(|s| RankingRule::from_str(s.as_ref()))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,8 +192,8 @@ impl Main {
|
|||
self.main.get::<_, Str, SerdeBincode<Vec<RankingRule>>>(reader, RANKING_RULES_KEY)
|
||||
}
|
||||
|
||||
pub fn put_ranking_rules(self, writer: &mut heed::RwTxn<MainT>, value: Vec<RankingRule>) -> ZResult<()> {
|
||||
self.main.put::<_, Str, SerdeBincode<Vec<RankingRule>>>(writer, RANKING_RULES_KEY, &value)
|
||||
pub fn put_ranking_rules(self, writer: &mut heed::RwTxn<MainT>, value: &[RankingRule]) -> ZResult<()> {
|
||||
self.main.put::<_, Str, SerdeBincode<Vec<RankingRule>>>(writer, RANKING_RULES_KEY, &value.to_vec())
|
||||
}
|
||||
|
||||
pub fn delete_ranking_rules(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
|
||||
|
@ -201,11 +201,14 @@ impl Main {
|
|||
}
|
||||
|
||||
pub fn ranking_distinct(&self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<String>> {
|
||||
self.main.get::<_, Str, SerdeBincode<String>>(reader, RANKING_DISTINCT_KEY)
|
||||
if let Some(value) = self.main.get::<_, Str, Str>(reader, RANKING_DISTINCT_KEY)? {
|
||||
return Ok(Some(value.to_owned()))
|
||||
}
|
||||
return Ok(None)
|
||||
}
|
||||
|
||||
pub fn put_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>, value: String) -> ZResult<()> {
|
||||
self.main.put::<_, Str, SerdeBincode<String>>(writer, RANKING_DISTINCT_KEY, &value)
|
||||
pub fn put_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>, value: &str) -> ZResult<()> {
|
||||
self.main.put::<_, Str, Str>(writer, RANKING_DISTINCT_KEY, value)
|
||||
}
|
||||
|
||||
pub fn delete_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
|
||||
|
|
|
@ -106,7 +106,7 @@ pub fn apply_documents_deletion(
|
|||
let mut words_document_ids = HashMap::new();
|
||||
for id in idset {
|
||||
// remove all the ranked attributes from the ranked_map
|
||||
for ranked_attr in &ranked_fields {
|
||||
for ranked_attr in ranked_fields {
|
||||
ranked_map.remove(id, *ranked_attr);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@ pub fn apply_settings_update(
|
|||
|
||||
match settings.ranking_rules {
|
||||
UpdateState::Update(v) => {
|
||||
let ranked_field: Vec<&str> = v.iter().filter_map(RankingRule::get_field).collect();
|
||||
let ranked_field: Vec<&str> = v.iter().filter_map(RankingRule::field).collect();
|
||||
schema.update_ranked(ranked_field)?;
|
||||
index.main.put_ranking_rules(writer, v)?;
|
||||
index.main.put_ranking_rules(writer, &v)?;
|
||||
must_reindex = true;
|
||||
},
|
||||
UpdateState::Clear => {
|
||||
|
@ -60,7 +60,7 @@ pub fn apply_settings_update(
|
|||
|
||||
match settings.ranking_distinct {
|
||||
UpdateState::Update(v) => {
|
||||
index.main.put_ranking_distinct(writer, v)?;
|
||||
index.main.put_ranking_distinct(writer, &v)?;
|
||||
},
|
||||
UpdateState::Clear => {
|
||||
index.main.delete_ranking_distinct(writer)?;
|
||||
|
@ -99,16 +99,12 @@ pub fn apply_settings_update(
|
|||
UpdateState::Nothing => (),
|
||||
};
|
||||
|
||||
match settings.identifier.clone() {
|
||||
UpdateState::Update(v) => {
|
||||
schema.set_identifier(v.as_ref())?;
|
||||
index.main.put_schema(writer, &schema)?;
|
||||
must_reindex = true;
|
||||
},
|
||||
_ => {
|
||||
index.main.put_schema(writer, &schema)?;
|
||||
},
|
||||
};
|
||||
if let UpdateState::Update(v) = settings.identifier.clone() {
|
||||
schema.set_identifier(v.as_ref())?;
|
||||
must_reindex = true;
|
||||
}
|
||||
|
||||
index.main.put_schema(writer, &schema)?;
|
||||
|
||||
match settings.stop_words {
|
||||
UpdateState::Update(stop_words) => {
|
||||
|
@ -121,13 +117,13 @@ pub fn apply_settings_update(
|
|||
must_reindex = true;
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
UpdateState::Nothing => (),
|
||||
}
|
||||
|
||||
match settings.synonyms {
|
||||
UpdateState::Update(synonyms) => apply_synonyms_update(writer, index, synonyms)?,
|
||||
UpdateState::Clear => apply_synonyms_update(writer, index, BTreeMap::new())?,
|
||||
_ => (),
|
||||
UpdateState::Nothing => (),
|
||||
}
|
||||
|
||||
if must_reindex {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue