mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-08 18:12:55 +00:00
Resolve some clippys, format (#1144)
* cargo +nightly clippy --fix -Z unstable-options
This commit is contained in:
@@ -86,12 +86,10 @@ impl Collector for StatsCollector {
|
||||
|
||||
fn merge_fruits(&self, segment_stats: Vec<Option<Stats>>) -> tantivy::Result<Option<Stats>> {
|
||||
let mut stats = Stats::default();
|
||||
for segment_stats_opt in segment_stats {
|
||||
if let Some(segment_stats) = segment_stats_opt {
|
||||
stats.count += segment_stats.count;
|
||||
stats.sum += segment_stats.sum;
|
||||
stats.squared_sum += segment_stats.squared_sum;
|
||||
}
|
||||
for segment_stats in segment_stats.into_iter().flatten() {
|
||||
stats.count += segment_stats.count;
|
||||
stats.sum += segment_stats.sum;
|
||||
stats.squared_sum += segment_stats.squared_sum;
|
||||
}
|
||||
Ok(stats.non_zero_count())
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ impl Index {
|
||||
|
||||
let mut damaged_files = HashSet::new();
|
||||
for path in active_existing_files {
|
||||
if !self.directory.validate_checksum(&path)? {
|
||||
if !self.directory.validate_checksum(path)? {
|
||||
damaged_files.insert((*path).clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +105,7 @@ impl CompositeFastFieldSerializer {
|
||||
&fastfield_accessor,
|
||||
&mut estimations,
|
||||
);
|
||||
if let Some(broken_estimation) = estimations
|
||||
.iter()
|
||||
.find(|estimation| estimation.0 == f32::NAN)
|
||||
if let Some(broken_estimation) = estimations.iter().find(|estimation| estimation.0.is_nan())
|
||||
{
|
||||
warn!(
|
||||
"broken estimation for fast field codec {}",
|
||||
|
||||
@@ -141,7 +141,7 @@ const LOREM: &str = "Doc Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
||||
fn get_text() -> String {
|
||||
use rand::seq::SliceRandom;
|
||||
let mut rng = thread_rng();
|
||||
let tokens: Vec<_> = LOREM.split(" ").collect();
|
||||
let tokens: Vec<_> = LOREM.split(' ').collect();
|
||||
let random_val = rng.gen_range(0..20);
|
||||
|
||||
(0..random_val)
|
||||
|
||||
@@ -150,7 +150,7 @@ impl TermOrdinalMapping {
|
||||
.iter()
|
||||
.flat_map(|term_ordinals| term_ordinals.iter().cloned().max())
|
||||
.max()
|
||||
.unwrap_or_else(TermOrdinal::default)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -966,7 +966,7 @@ impl IndexMerger {
|
||||
doc_id_and_positions.sort_unstable_by_key(|&(doc_id, _, _)| doc_id);
|
||||
|
||||
for (doc_id, term_freq, positions) in &doc_id_and_positions {
|
||||
let delta_positions = delta_computer.compute_delta(&positions);
|
||||
let delta_positions = delta_computer.compute_delta(positions);
|
||||
field_serializer.write_doc(*doc_id, *term_freq, delta_positions);
|
||||
}
|
||||
doc_id_and_positions.clear();
|
||||
|
||||
@@ -260,9 +260,7 @@ mod tests {
|
||||
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
|
||||
assert_eq!(
|
||||
postings.doc_freq_given_deletes(
|
||||
segment_reader
|
||||
.delete_bitset()
|
||||
.unwrap_or_else(|| &&fallback_bitset)
|
||||
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
|
||||
),
|
||||
2
|
||||
);
|
||||
@@ -341,9 +339,7 @@ mod tests {
|
||||
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
|
||||
assert_eq!(
|
||||
postings.doc_freq_given_deletes(
|
||||
segment_reader
|
||||
.delete_bitset()
|
||||
.unwrap_or_else(|| &&fallback_bitset)
|
||||
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
|
||||
),
|
||||
2
|
||||
);
|
||||
@@ -453,9 +449,7 @@ mod tests {
|
||||
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
|
||||
assert_eq!(
|
||||
postings.doc_freq_given_deletes(
|
||||
segment_reader
|
||||
.delete_bitset()
|
||||
.unwrap_or_else(|| &&fallback_bitset)
|
||||
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
|
||||
),
|
||||
2
|
||||
);
|
||||
|
||||
@@ -209,7 +209,7 @@ impl BlockSegmentPostings {
|
||||
#[inline]
|
||||
pub(crate) fn full_block(&self) -> &[DocId; COMPRESSION_BLOCK_SIZE] {
|
||||
debug_assert!(self.block_is_loaded());
|
||||
&self.doc_decoder.full_output()
|
||||
self.doc_decoder.full_output()
|
||||
}
|
||||
|
||||
/// Return the document at index `idx` of the block.
|
||||
|
||||
@@ -443,10 +443,8 @@ impl<W: Write> PostingsSerializer<W> {
|
||||
let skip_data = self.skip_write.data();
|
||||
VInt(skip_data.len() as u64).serialize(&mut self.output_write)?;
|
||||
self.output_write.write_all(skip_data)?;
|
||||
self.output_write.write_all(&self.postings_write[..])?;
|
||||
} else {
|
||||
self.output_write.write_all(&self.postings_write[..])?;
|
||||
}
|
||||
self.output_write.write_all(&self.postings_write[..])?;
|
||||
self.skip_write.clear();
|
||||
self.postings_write.clear();
|
||||
self.bm25_weight = None;
|
||||
|
||||
@@ -121,10 +121,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn is_match(&self, state: &Self::State) -> bool {
|
||||
match *state {
|
||||
State::AfterA => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*state, State::AfterA)
|
||||
}
|
||||
|
||||
fn accept(&self, state: &Self::State, byte: u8) -> Self::State {
|
||||
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
));
|
||||
let query = BooleanQuery::from(vec![(Occur::Should, term_a), (Occur::Should, term_b)]);
|
||||
let explanation = query.explain(&searcher, DocAddress::new(0, 0u32))?;
|
||||
assert_nearly_equals!(explanation.value(), 0.6931472);
|
||||
assert_nearly_equals!(explanation.value(), std::f32::consts::LN_2);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ pub use self::int_options::IntOptions;
|
||||
/// A field name can be any character, must have at least one character
|
||||
/// and must not start with a `-`.
|
||||
pub fn is_valid_field_name(field_name: &str) -> bool {
|
||||
field_name.len() > 0 && !field_name.starts_with('-')
|
||||
!field_name.is_empty() && !field_name.starts_with('-')
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user