mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Merge pull request #44 from meilisearch/clippy
Fix some clippy warnings
This commit is contained in:
commit
e4c2abb1d9
@ -25,7 +25,7 @@ impl<'a> Mdfs<'a> {
|
|||||||
) -> Mdfs<'a>
|
) -> Mdfs<'a>
|
||||||
{
|
{
|
||||||
// Compute the number of pairs (windows) we have for this list of words.
|
// 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;
|
let max_mana = mana * 8;
|
||||||
Mdfs { index, rtxn, words, union_cache: HashMap::new(), candidates, mana, max_mana }
|
Mdfs { index, rtxn, words, union_cache: HashMap::new(), candidates, mana, max_mana }
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ impl<'a> Iterator for Mdfs<'a> {
|
|||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
// We always increase the mana for the next loop.
|
// We always increase the mana for the next loop.
|
||||||
let proximity = self.mana;
|
let proximity = self.mana;
|
||||||
self.mana = self.mana + 1;
|
self.mana += 1;
|
||||||
|
|
||||||
// If no documents were found we must not return and continue
|
// If no documents were found we must not return and continue
|
||||||
// the search with more mana.
|
// the search with more mana.
|
||||||
|
@ -224,7 +224,7 @@ impl FacetCondition {
|
|||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
Err(PestError::<Rule>::new_from_span(
|
Err(PestError::<Rule>::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!("invalid operator on a faceted string"),
|
message: "invalid operator on a faceted string".to_string(),
|
||||||
},
|
},
|
||||||
item_span,
|
item_span,
|
||||||
).into())
|
).into())
|
||||||
@ -264,7 +264,7 @@ impl FacetCondition {
|
|||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
Err(PestError::<Rule>::new_from_span(
|
Err(PestError::<Rule>::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!("invalid operator on a faceted string"),
|
message: "invalid operator on a faceted string".to_string(),
|
||||||
},
|
},
|
||||||
item_span,
|
item_span,
|
||||||
).into())
|
).into())
|
||||||
@ -288,7 +288,7 @@ impl FacetCondition {
|
|||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
Err(PestError::<Rule>::new_from_span(
|
Err(PestError::<Rule>::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!("invalid operator on a faceted string"),
|
message: "invalid operator on a faceted string".to_string(),
|
||||||
},
|
},
|
||||||
item_span,
|
item_span,
|
||||||
).into())
|
).into())
|
||||||
@ -312,7 +312,7 @@ impl FacetCondition {
|
|||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
Err(PestError::<Rule>::new_from_span(
|
Err(PestError::<Rule>::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!("invalid operator on a faceted string"),
|
message: "invalid operator on a faceted string".to_string(),
|
||||||
},
|
},
|
||||||
item_span,
|
item_span,
|
||||||
).into())
|
).into())
|
||||||
@ -336,7 +336,7 @@ impl FacetCondition {
|
|||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
Err(PestError::<Rule>::new_from_span(
|
Err(PestError::<Rule>::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
ErrorVariant::CustomError {
|
||||||
message: format!("invalid operator on a faceted string"),
|
message: "invalid operator on a faceted string".to_string(),
|
||||||
},
|
},
|
||||||
item_span,
|
item_span,
|
||||||
).into())
|
).into())
|
||||||
@ -508,7 +508,7 @@ impl FacetCondition {
|
|||||||
let all_documents_ids = index.faceted_documents_ids(rtxn, field_id)?;
|
let all_documents_ids = index.faceted_documents_ids(rtxn, field_id)?;
|
||||||
let op = FacetStringOperator::Equal(string.clone());
|
let op = FacetStringOperator::Equal(string.clone());
|
||||||
let docids = Self::evaluate_string_operator(rtxn, index, db, field_id, &op)?;
|
let docids = Self::evaluate_string_operator(rtxn, index, db, field_id, &op)?;
|
||||||
return Ok(all_documents_ids - docids);
|
Ok(all_documents_ids - docids)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ pub fn run(opt: Opt) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let lines = match opt.query {
|
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 = _>>,
|
None => Box::new(stdin.lock().lines()) as Box<dyn Iterator<Item = _>>,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,14 +66,13 @@ impl CharCategory {
|
|||||||
fn new(c: char) -> Self {
|
fn new(c: char) -> Self {
|
||||||
if c.is_alphanumeric() {
|
if c.is_alphanumeric() {
|
||||||
if is_chinese(c) { Chinese } else { Alphanumeric }
|
if is_chinese(c) { Chinese } else { Alphanumeric }
|
||||||
} else {
|
} else if c.is_whitespace() { Space } else { Other }
|
||||||
if c.is_whitespace() { Space } else { Other }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_chinese(c: char) -> bool {
|
fn is_chinese(c: char) -> bool {
|
||||||
match u32::from(c) {
|
matches!(
|
||||||
|
u32::from(c),
|
||||||
0x4E00..=0x9FEF
|
0x4E00..=0x9FEF
|
||||||
| 0x3400..=0x4DBF
|
| 0x3400..=0x4DBF
|
||||||
| 0x20000..=0x2A6DF
|
| 0x20000..=0x2A6DF
|
||||||
@ -81,9 +80,8 @@ fn is_chinese(c: char) -> bool {
|
|||||||
| 0x2B740..=0x2B81F
|
| 0x2B740..=0x2B81F
|
||||||
| 0x2B820..=0x2CEAF
|
| 0x2B820..=0x2CEAF
|
||||||
| 0x2CEB0..=0x2EBEF
|
| 0x2CEB0..=0x2EBEF
|
||||||
| 0x3007..=0x3007 => true,
|
| 0x3007..=0x3007
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the longest key that is prefix of the given value.
|
/// Find the longest key that is prefix of the given value.
|
||||||
|
@ -273,9 +273,9 @@ impl<'t, 'u, 'i, 'a> IndexDocuments<'t, 'u, 'i, 'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let output = match self.update_format {
|
let output = match self.update_format {
|
||||||
UpdateFormat::Csv => transform.from_csv(reader, &progress_callback)?,
|
UpdateFormat::Csv => transform.output_from_csv(reader, &progress_callback)?,
|
||||||
UpdateFormat::Json => transform.from_json(reader, &progress_callback)?,
|
UpdateFormat::Json => transform.output_from_json(reader, &progress_callback)?,
|
||||||
UpdateFormat::JsonStream => transform.from_json_stream(reader, &progress_callback)?,
|
UpdateFormat::JsonStream => transform.output_from_json_stream(reader, &progress_callback)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Update transformed in {:.02?}", before_transform.elapsed());
|
info!("Update transformed in {:.02?}", before_transform.elapsed());
|
||||||
|
@ -440,7 +440,7 @@ impl Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute the document id of the next document.
|
// Compute the document id of the next document.
|
||||||
count = count + 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress_callback(UpdateIndexingStep::IndexDocuments {
|
progress_callback(UpdateIndexingStep::IndexDocuments {
|
||||||
@ -527,12 +527,10 @@ fn compute_words_pair_proximities(
|
|||||||
let prox = u8::try_from(prox).unwrap();
|
let prox = u8::try_from(prox).unwrap();
|
||||||
// We don't care about a word that appear at the
|
// We don't care about a word that appear at the
|
||||||
// same position or too far from the other.
|
// same position or too far from the other.
|
||||||
if prox >= 1 && prox <= 7 {
|
if prox >= 1 && prox <= 7 && min_prox.map_or(true, |mp| prox < mp) {
|
||||||
if min_prox.map_or(true, |mp| prox < mp) {
|
|
||||||
min_prox = Some(prox)
|
min_prox = Some(prox)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(min_prox) = min_prox {
|
if let Some(min_prox) = min_prox {
|
||||||
words_pair_proximities.insert((w1.as_str(), w2.as_str()), min_prox);
|
words_pair_proximities.insert((w1.as_str(), w2.as_str()), min_prox);
|
||||||
@ -569,18 +567,28 @@ fn parse_facet_value(ftype: FacetType, value: &Value) -> anyhow::Result<SmallVec
|
|||||||
{
|
{
|
||||||
match value {
|
match value {
|
||||||
Value::Null => Ok(()),
|
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 {
|
Value::Number(number) => match ftype {
|
||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
let string = SmallString32::from(number.to_string());
|
let string = SmallString32::from(number.to_string());
|
||||||
Ok(output.push(String(string)))
|
output.push(String(string));
|
||||||
|
Ok(())
|
||||||
},
|
},
|
||||||
FacetType::Float => match number.as_f64() {
|
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),
|
None => bail!("invalid facet type, expecting {} found integer", ftype),
|
||||||
},
|
},
|
||||||
FacetType::Integer => match number.as_i64() {
|
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() {
|
None => if number.is_f64() {
|
||||||
bail!("invalid facet type, expecting {} found float", ftype)
|
bail!("invalid facet type, expecting {} found float", ftype)
|
||||||
} else {
|
} else {
|
||||||
@ -594,14 +602,21 @@ fn parse_facet_value(ftype: FacetType, value: &Value) -> anyhow::Result<SmallVec
|
|||||||
match ftype {
|
match ftype {
|
||||||
FacetType::String => {
|
FacetType::String => {
|
||||||
let string = SmallString32::from(string);
|
let string = SmallString32::from(string);
|
||||||
Ok(output.push(String(string)))
|
output.push(String(string));
|
||||||
|
Ok(())
|
||||||
},
|
},
|
||||||
FacetType::Float => match string.parse() {
|
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),
|
Err(_err) => bail!("invalid facet type, expecting {} found string", ftype),
|
||||||
},
|
},
|
||||||
FacetType::Integer => match string.parse() {
|
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),
|
Err(_err) => bail!("invalid facet type, expecting {} found string", ftype),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
@ -46,23 +45,23 @@ pub struct Transform<'t, 'i> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transform<'_, '_> {
|
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
|
where
|
||||||
R: Read,
|
R: Read,
|
||||||
F: Fn(UpdateIndexingStep) + Sync,
|
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
|
where
|
||||||
R: Read,
|
R: Read,
|
||||||
F: Fn(UpdateIndexingStep) + Sync,
|
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,
|
self,
|
||||||
reader: R,
|
reader: R,
|
||||||
is_stream: bool,
|
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
|
// 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.
|
// give it to the last transforming function which returns the TransformOutput.
|
||||||
self.from_sorter(
|
self.output_from_sorter(
|
||||||
sorter,
|
sorter,
|
||||||
primary_key,
|
primary_key,
|
||||||
fields_ids_map,
|
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
|
where
|
||||||
R: Read,
|
R: Read,
|
||||||
F: Fn(UpdateIndexingStep) + Sync,
|
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
|
// 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.
|
// give it to the last transforming function which returns the TransformOutput.
|
||||||
self.from_sorter(
|
self.output_from_sorter(
|
||||||
sorter,
|
sorter,
|
||||||
primary_key_field_id,
|
primary_key_field_id,
|
||||||
fields_ids_map,
|
fields_ids_map,
|
||||||
@ -363,7 +362,7 @@ impl Transform<'_, '_> {
|
|||||||
/// Generate the `TransformOutput` based on the given sorter that can be generated from any
|
/// 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
|
/// 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.
|
/// 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,
|
self,
|
||||||
sorter: grenad::Sorter<MergeFn>,
|
sorter: grenad::Sorter<MergeFn>,
|
||||||
primary_key: u8,
|
primary_key: u8,
|
||||||
@ -408,7 +407,6 @@ impl Transform<'_, '_> {
|
|||||||
Some(docid) => {
|
Some(docid) => {
|
||||||
// If we find the user id in the current external documents ids map
|
// 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.
|
// 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);
|
replaced_documents_ids.insert(docid);
|
||||||
|
|
||||||
// Depending on the update indexing method we will merge
|
// Depending on the update indexing method we will merge
|
||||||
|
@ -134,3 +134,9 @@ impl<'a> UpdateBuilder<'a> {
|
|||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for UpdateBuilder<'_> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user