diff --git a/src/mdfs.rs b/src/mdfs.rs index 3182fa96e..6beba3c69 100644 --- a/src/mdfs.rs +++ b/src/mdfs.rs @@ -25,7 +25,7 @@ impl<'a> Mdfs<'a> { ) -> Mdfs<'a> { // Compute the number of pairs (windows) we have for this list of words. - let mana = words.len().checked_sub(1).unwrap_or(0) as u32; + let mana = words.len().saturating_sub(1) as u32; let max_mana = mana * 8; Mdfs { index, rtxn, words, union_cache: HashMap::new(), candidates, mana, max_mana } } @@ -59,7 +59,7 @@ impl<'a> Iterator for Mdfs<'a> { Ok(()) => { // We always increase the mana for the next loop. let proximity = self.mana; - self.mana = self.mana + 1; + self.mana += 1; // If no documents were found we must not return and continue // the search with more mana. diff --git a/src/search/facet/mod.rs b/src/search/facet/mod.rs index 7717e2c03..c47f290e0 100644 --- a/src/search/facet/mod.rs +++ b/src/search/facet/mod.rs @@ -224,7 +224,7 @@ impl FacetCondition { FacetType::String => { Err(PestError::::new_from_span( ErrorVariant::CustomError { - message: format!("invalid operator on a faceted string"), + message: "invalid operator on a faceted string".to_string(), }, item_span, ).into()) @@ -264,7 +264,7 @@ impl FacetCondition { FacetType::String => { Err(PestError::::new_from_span( ErrorVariant::CustomError { - message: format!("invalid operator on a faceted string"), + message: "invalid operator on a faceted string".to_string(), }, item_span, ).into()) @@ -288,7 +288,7 @@ impl FacetCondition { FacetType::String => { Err(PestError::::new_from_span( ErrorVariant::CustomError { - message: format!("invalid operator on a faceted string"), + message: "invalid operator on a faceted string".to_string(), }, item_span, ).into()) @@ -312,7 +312,7 @@ impl FacetCondition { FacetType::String => { Err(PestError::::new_from_span( ErrorVariant::CustomError { - message: format!("invalid operator on a faceted string"), + message: "invalid operator on a faceted string".to_string(), }, item_span, ).into()) @@ -336,7 +336,7 @@ impl FacetCondition { FacetType::String => { Err(PestError::::new_from_span( ErrorVariant::CustomError { - message: format!("invalid operator on a faceted string"), + message: "invalid operator on a faceted string".to_string(), }, item_span, ).into()) @@ -508,7 +508,7 @@ impl FacetCondition { let all_documents_ids = index.faceted_documents_ids(rtxn, field_id)?; let op = FacetStringOperator::Equal(string.clone()); let docids = Self::evaluate_string_operator(rtxn, index, db, field_id, &op)?; - return Ok(all_documents_ids - docids); + Ok(all_documents_ids - docids) }, } } diff --git a/src/subcommand/search.rs b/src/subcommand/search.rs index 358805a0b..13b306d47 100644 --- a/src/subcommand/search.rs +++ b/src/subcommand/search.rs @@ -49,7 +49,7 @@ pub fn run(opt: Opt) -> anyhow::Result<()> { let stdin = io::stdin(); let lines = match opt.query { - Some(query) => Box::new(once(Ok(query.to_string()))), + Some(query) => Box::new(once(Ok(query))), None => Box::new(stdin.lock().lines()) as Box>, }; diff --git a/src/tokenizer.rs b/src/tokenizer.rs index fe65c6dfc..c64f5c360 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -66,14 +66,13 @@ impl CharCategory { fn new(c: char) -> Self { if c.is_alphanumeric() { if is_chinese(c) { Chinese } else { Alphanumeric } - } else { - if c.is_whitespace() { Space } else { Other } - } + } else if c.is_whitespace() { Space } else { Other } } } fn is_chinese(c: char) -> bool { - match u32::from(c) { + matches!( + u32::from(c), 0x4E00..=0x9FEF | 0x3400..=0x4DBF | 0x20000..=0x2A6DF @@ -81,9 +80,8 @@ fn is_chinese(c: char) -> bool { | 0x2B740..=0x2B81F | 0x2B820..=0x2CEAF | 0x2CEB0..=0x2EBEF - | 0x3007..=0x3007 => true, - _ => false, - } + | 0x3007..=0x3007 + ) } /// Find the longest key that is prefix of the given value. diff --git a/src/update/index_documents/mod.rs b/src/update/index_documents/mod.rs index 4a3ec43f9..796a0910a 100644 --- a/src/update/index_documents/mod.rs +++ b/src/update/index_documents/mod.rs @@ -273,9 +273,9 @@ impl<'t, 'u, 'i, 'a> IndexDocuments<'t, 'u, 'i, 'a> { }; let output = match self.update_format { - UpdateFormat::Csv => transform.from_csv(reader, &progress_callback)?, - UpdateFormat::Json => transform.from_json(reader, &progress_callback)?, - UpdateFormat::JsonStream => transform.from_json_stream(reader, &progress_callback)?, + UpdateFormat::Csv => transform.output_from_csv(reader, &progress_callback)?, + UpdateFormat::Json => transform.output_from_json(reader, &progress_callback)?, + UpdateFormat::JsonStream => transform.output_from_json_stream(reader, &progress_callback)?, }; info!("Update transformed in {:.02?}", before_transform.elapsed()); diff --git a/src/update/index_documents/store.rs b/src/update/index_documents/store.rs index 25c343910..57f99c908 100644 --- a/src/update/index_documents/store.rs +++ b/src/update/index_documents/store.rs @@ -440,7 +440,7 @@ impl Store { } // Compute the document id of the next document. - count = count + 1; + count += 1; } progress_callback(UpdateIndexingStep::IndexDocuments { @@ -527,10 +527,8 @@ fn compute_words_pair_proximities( let prox = u8::try_from(prox).unwrap(); // We don't care about a word that appear at the // same position or too far from the other. - if prox >= 1 && prox <= 7 { - if min_prox.map_or(true, |mp| prox < mp) { - min_prox = Some(prox) - } + if prox >= 1 && prox <= 7 && min_prox.map_or(true, |mp| prox < mp) { + min_prox = Some(prox) } } @@ -569,18 +567,28 @@ fn parse_facet_value(ftype: FacetType, value: &Value) -> anyhow::Result Ok(()), - Value::Bool(b) => Ok(output.push(Integer(*b as i64))), + Value::Bool(b) => { + output.push(Integer(*b as i64)); + Ok(()) + }, Value::Number(number) => match ftype { FacetType::String => { let string = SmallString32::from(number.to_string()); - Ok(output.push(String(string))) + output.push(String(string)); + Ok(()) }, FacetType::Float => match number.as_f64() { - Some(float) => Ok(output.push(Float(OrderedFloat(float)))), + Some(float) => { + output.push(Float(OrderedFloat(float))); + Ok(()) + }, None => bail!("invalid facet type, expecting {} found integer", ftype), }, FacetType::Integer => match number.as_i64() { - Some(integer) => Ok(output.push(Integer(integer))), + Some(integer) => { + output.push(Integer(integer)); + Ok(()) + }, None => if number.is_f64() { bail!("invalid facet type, expecting {} found float", ftype) } else { @@ -594,14 +602,21 @@ fn parse_facet_value(ftype: FacetType, value: &Value) -> anyhow::Result { let string = SmallString32::from(string); - Ok(output.push(String(string))) + output.push(String(string)); + Ok(()) }, FacetType::Float => match string.parse() { - Ok(float) => Ok(output.push(Float(OrderedFloat(float)))), + Ok(float) => { + output.push(Float(OrderedFloat(float))); + Ok(()) + }, Err(_err) => bail!("invalid facet type, expecting {} found string", ftype), }, FacetType::Integer => match string.parse() { - Ok(integer) => Ok(output.push(Integer(integer))), + Ok(integer) => { + output.push(Integer(integer)); + Ok(()) + }, Err(_err) => bail!("invalid facet type, expecting {} found string", ftype), }, } diff --git a/src/update/index_documents/transform.rs b/src/update/index_documents/transform.rs index 54619ed4f..a42da45f1 100644 --- a/src/update/index_documents/transform.rs +++ b/src/update/index_documents/transform.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::convert::TryFrom; use std::fs::File; use std::io::{Read, Seek, SeekFrom}; use std::iter::Peekable; @@ -46,23 +45,23 @@ pub struct Transform<'t, 'i> { } impl Transform<'_, '_> { - pub fn from_json(self, reader: R, progress_callback: F) -> anyhow::Result + pub fn output_from_json(self, reader: R, progress_callback: F) -> anyhow::Result where R: Read, F: Fn(UpdateIndexingStep) + Sync, { - self.from_generic_json(reader, false, progress_callback) + self.output_from_generic_json(reader, false, progress_callback) } - pub fn from_json_stream(self, reader: R, progress_callback: F) -> anyhow::Result + pub fn output_from_json_stream(self, reader: R, progress_callback: F) -> anyhow::Result where R: Read, F: Fn(UpdateIndexingStep) + Sync, { - self.from_generic_json(reader, true, progress_callback) + self.output_from_generic_json(reader, true, progress_callback) } - fn from_generic_json( + fn output_from_generic_json( self, reader: R, is_stream: bool, @@ -221,7 +220,7 @@ impl Transform<'_, '_> { // Now that we have a valid sorter that contains the user id and the obkv we // give it to the last transforming function which returns the TransformOutput. - self.from_sorter( + self.output_from_sorter( sorter, primary_key, fields_ids_map, @@ -231,7 +230,7 @@ impl Transform<'_, '_> { ) } - pub fn from_csv(self, reader: R, progress_callback: F) -> anyhow::Result + pub fn output_from_csv(self, reader: R, progress_callback: F) -> anyhow::Result where R: Read, F: Fn(UpdateIndexingStep) + Sync, @@ -350,7 +349,7 @@ impl Transform<'_, '_> { // Now that we have a valid sorter that contains the user id and the obkv we // give it to the last transforming function which returns the TransformOutput. - self.from_sorter( + self.output_from_sorter( sorter, primary_key_field_id, fields_ids_map, @@ -363,7 +362,7 @@ impl Transform<'_, '_> { /// Generate the `TransformOutput` based on the given sorter that can be generated from any /// format like CSV, JSON or JSON stream. This sorter must contain a key that is the document /// id for the user side and the value must be an obkv where keys are valid fields ids. - fn from_sorter( + fn output_from_sorter( self, sorter: grenad::Sorter, primary_key: u8, @@ -408,7 +407,6 @@ impl Transform<'_, '_> { Some(docid) => { // If we find the user id in the current external documents ids map // we use it and insert it in the list of replaced documents. - let docid = u32::try_from(docid).expect("valid document id"); replaced_documents_ids.insert(docid); // Depending on the update indexing method we will merge diff --git a/src/update/update_builder.rs b/src/update/update_builder.rs index b973bd535..43e3c28ed 100644 --- a/src/update/update_builder.rs +++ b/src/update/update_builder.rs @@ -134,3 +134,9 @@ impl<'a> UpdateBuilder<'a> { builder } } + +impl Default for UpdateBuilder<'_> { + fn default() -> Self { + Self::new() + } +}