Done a big clippy pass

This commit is contained in:
Kerollmops 2020-12-01 14:25:17 +01:00
parent 6e3f4e5e45
commit d0240bd9d0
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
8 changed files with 59 additions and 42 deletions

View File

@ -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.

View File

@ -224,7 +224,7 @@ impl FacetCondition {
FacetType::String => {
Err(PestError::<Rule>::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::<Rule>::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::<Rule>::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::<Rule>::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::<Rule>::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)
},
}
}

View File

@ -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<dyn Iterator<Item = _>>,
};

View File

@ -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.

View File

@ -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());

View File

@ -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<SmallVec
{
match value {
Value::Null => 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<SmallVec
match ftype {
FacetType::String => {
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),
},
}

View File

@ -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<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
pub fn output_from_json<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
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<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
pub fn output_from_json_stream<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
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<R, F>(
fn output_from_generic_json<R, F>(
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<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
pub fn output_from_csv<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<TransformOutput>
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<F>(
fn output_from_sorter<F>(
self,
sorter: grenad::Sorter<MergeFn>,
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

View File

@ -134,3 +134,9 @@ impl<'a> UpdateBuilder<'a> {
builder
}
}
impl Default for UpdateBuilder<'_> {
fn default() -> Self {
Self::new()
}
}