From 9dce41ed6ba9b57bf7ce2503e4dfe5c048ab3414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 18 Oct 2019 13:21:41 +0200 Subject: [PATCH] Cargo clippy pass --- meilidb-core/src/automaton/query_enhancer.rs | 2 +- meilidb-core/src/query_builder.rs | 38 +++++++++---------- meilidb-core/src/ranked_map.rs | 4 ++ meilidb-core/src/raw_indexer.rs | 6 +++ meilidb-core/src/serde/mod.rs | 6 +++ meilidb-core/src/store/docs_words.rs | 6 +-- meilidb-core/src/store/documents_fields.rs | 10 ++--- .../src/store/documents_fields_counts.rs | 18 ++++----- meilidb-core/src/store/main.rs | 24 ++++++------ meilidb-core/src/store/mod.rs | 2 +- meilidb-core/src/store/postings_lists.rs | 6 +-- meilidb-core/src/store/synonyms.rs | 6 +-- meilidb-core/src/store/updates.rs | 10 ++--- meilidb-core/src/store/updates_results.rs | 6 +-- meilidb-core/src/update/schema_update.rs | 2 +- meilidb-tokenizer/src/lib.rs | 2 +- 16 files changed, 82 insertions(+), 66 deletions(-) diff --git a/meilidb-core/src/automaton/query_enhancer.rs b/meilidb-core/src/automaton/query_enhancer.rs index 7a949934b..2194f3ff1 100644 --- a/meilidb-core/src/automaton/query_enhancer.rs +++ b/meilidb-core/src/automaton/query_enhancer.rs @@ -102,7 +102,7 @@ pub struct QueryEnhancerBuilder<'a, S> { impl> QueryEnhancerBuilder<'_, S> { pub fn new(query: &[S]) -> QueryEnhancerBuilder { // we initialize origins query indices based on their positions - let origins: Vec<_> = (0..query.len() + 1).collect(); + let origins: Vec<_> = (0..=query.len()).collect(); let real_to_origin = origins.iter().map(|&o| (o..o + 1, (o, 1))).collect(); QueryEnhancerBuilder { diff --git a/meilidb-core/src/query_builder.rs b/meilidb-core/src/query_builder.rs index 6226067c7..3d0769ec3 100644 --- a/meilidb-core/src/query_builder.rs +++ b/meilidb-core/src/query_builder.rs @@ -57,7 +57,7 @@ fn multiword_rewrite_matches( let match_ = TmpMatch { query_index, word_index, - ..match_.clone() + ..*match_ }; padded_matches.push((*id, match_)); } @@ -72,7 +72,7 @@ fn multiword_rewrite_matches( let padmatch = TmpMatch { query_index, word_index, - ..match_.clone() + ..*match_ }; for (_, nmatch_) in next_group { @@ -89,7 +89,7 @@ fn multiword_rewrite_matches( let match_ = TmpMatch { query_index, word_index, - ..match_.clone() + ..*match_ }; padded_matches.push((*id, match_)); biggest = biggest.max(i + 1); @@ -116,7 +116,7 @@ fn multiword_rewrite_matches( let match_ = TmpMatch { query_index, word_index, - ..match_.clone() + ..*match_ }; padded_matches.push((*id, match_)); } @@ -141,9 +141,9 @@ fn fetch_raw_documents( automatons: &[Automaton], query_enhancer: &QueryEnhancer, searchables: Option<&ReorderedAttrs>, - main_store: &store::Main, - postings_lists_store: &store::PostingsLists, - documents_fields_counts_store: &store::DocumentsFieldsCounts, + main_store: store::Main, + postings_lists_store: store::PostingsLists, + documents_fields_counts_store: store::DocumentsFieldsCounts, ) -> MResult> { let mut matches = Vec::new(); let mut highlights = Vec::new(); @@ -370,11 +370,11 @@ where let (automaton_producer, query_enhancer) = AutomatonProducer::new(reader, query, main_store, synonyms_store)?; - let mut automaton_producer = automaton_producer.into_iter(); + let automaton_producer = automaton_producer.into_iter(); let mut automatons = Vec::new(); // aggregate automatons groups by groups after time - while let Some(auts) = automaton_producer.next() { + for auts in automaton_producer { automatons.extend(auts); // we must retrieve the documents associated @@ -384,9 +384,9 @@ where &automatons, &query_enhancer, searchable_attrs.as_ref(), - &main_store, - &postings_lists_store, - &documents_fields_counts_store, + main_store, + postings_lists_store, + documents_fields_counts_store, )?; // stop processing when time is running out @@ -447,7 +447,7 @@ where // those must be returned let documents = raw_documents_processed .into_iter() - .map(|d| Document::from_raw(d)) + .map(Document::from_raw) .collect(); Ok(documents) @@ -483,11 +483,11 @@ where let (automaton_producer, query_enhancer) = AutomatonProducer::new(reader, query, main_store, synonyms_store)?; - let mut automaton_producer = automaton_producer.into_iter(); + let automaton_producer = automaton_producer.into_iter(); let mut automatons = Vec::new(); // aggregate automatons groups by groups after time - while let Some(auts) = automaton_producer.next() { + for auts in automaton_producer { automatons.extend(auts); // we must retrieve the documents associated @@ -497,9 +497,9 @@ where &automatons, &query_enhancer, searchable_attrs.as_ref(), - &main_store, - &postings_lists_store, - &documents_fields_counts_store, + main_store, + postings_lists_store, + documents_fields_counts_store, )?; // stop processing when time is running out @@ -620,7 +620,7 @@ where // those must be returned let documents = raw_documents_processed .into_iter() - .map(|d| Document::from_raw(d)) + .map(Document::from_raw) .collect(); Ok(documents) diff --git a/meilidb-core/src/ranked_map.rs b/meilidb-core/src/ranked_map.rs index da34e2ff0..2675339eb 100644 --- a/meilidb-core/src/ranked_map.rs +++ b/meilidb-core/src/ranked_map.rs @@ -15,6 +15,10 @@ impl RankedMap { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + pub fn insert(&mut self, document: DocumentId, attribute: SchemaAttr, number: Number) { self.0.insert((document, attribute), number); } diff --git a/meilidb-core/src/raw_indexer.rs b/meilidb-core/src/raw_indexer.rs index 615855187..396134436 100644 --- a/meilidb-core/src/raw_indexer.rs +++ b/meilidb-core/src/raw_indexer.rs @@ -152,6 +152,12 @@ impl RawIndexer { } } +impl Default for RawIndexer { + fn default() -> Self { + Self::new() + } +} + fn index_token( token: Token, id: DocumentId, diff --git a/meilidb-core/src/serde/mod.rs b/meilidb-core/src/serde/mod.rs index 47a0926ca..c2feafbf0 100644 --- a/meilidb-core/src/serde/mod.rs +++ b/meilidb-core/src/serde/mod.rs @@ -119,3 +119,9 @@ impl RamDocumentStore { self.0 } } + +impl Default for RamDocumentStore { + fn default() -> Self { + Self::new() + } +} diff --git a/meilidb-core/src/store/docs_words.rs b/meilidb-core/src/store/docs_words.rs index d52c4b2c6..93d4192e3 100644 --- a/meilidb-core/src/store/docs_words.rs +++ b/meilidb-core/src/store/docs_words.rs @@ -11,7 +11,7 @@ pub struct DocsWords { impl DocsWords { pub fn put_doc_words( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, words: &fst::Set, @@ -22,7 +22,7 @@ impl DocsWords { } pub fn del_doc_words( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, ) -> ZResult { @@ -31,7 +31,7 @@ impl DocsWords { } pub fn doc_words( - &self, + self, reader: &zlmdb::RoTxn, document_id: DocumentId, ) -> ZResult> { diff --git a/meilidb-core/src/store/documents_fields.rs b/meilidb-core/src/store/documents_fields.rs index ee5bde1b3..84b53351b 100644 --- a/meilidb-core/src/store/documents_fields.rs +++ b/meilidb-core/src/store/documents_fields.rs @@ -12,7 +12,7 @@ pub struct DocumentsFields { impl DocumentsFields { pub fn put_document_field( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, attribute: SchemaAttr, @@ -23,7 +23,7 @@ impl DocumentsFields { } pub fn del_all_document_fields( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, ) -> ZResult { @@ -33,7 +33,7 @@ impl DocumentsFields { } pub fn document_attribute<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, document_id: DocumentId, attribute: SchemaAttr, @@ -43,7 +43,7 @@ impl DocumentsFields { } pub fn document_fields<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, document_id: DocumentId, ) -> ZResult> { @@ -67,7 +67,7 @@ impl<'txn> Iterator for DocumentFieldsIter<'txn> { let attr = SchemaAttr(key.attr.get()); Some(Ok((attr, bytes))) } - Some(Err(e)) => Some(Err(e.into())), + Some(Err(e)) => Some(Err(e)), None => None, } } diff --git a/meilidb-core/src/store/documents_fields_counts.rs b/meilidb-core/src/store/documents_fields_counts.rs index 379687e5b..b765c8f25 100644 --- a/meilidb-core/src/store/documents_fields_counts.rs +++ b/meilidb-core/src/store/documents_fields_counts.rs @@ -11,7 +11,7 @@ pub struct DocumentsFieldsCounts { impl DocumentsFieldsCounts { pub fn put_document_field_count( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, attribute: SchemaAttr, @@ -22,7 +22,7 @@ impl DocumentsFieldsCounts { } pub fn del_all_document_fields_counts( - &self, + self, writer: &mut zlmdb::RwTxn, document_id: DocumentId, ) -> ZResult { @@ -33,7 +33,7 @@ impl DocumentsFieldsCounts { } pub fn document_field_count( - &self, + self, reader: &zlmdb::RoTxn, document_id: DocumentId, attribute: SchemaAttr, @@ -46,7 +46,7 @@ impl DocumentsFieldsCounts { } pub fn document_fields_counts<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, document_id: DocumentId, ) -> ZResult> { @@ -57,7 +57,7 @@ impl DocumentsFieldsCounts { } pub fn documents_ids<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, ) -> ZResult> { let iter = self.documents_fields_counts.iter(reader)?; @@ -68,7 +68,7 @@ impl DocumentsFieldsCounts { } pub fn all_documents_fields_counts<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, ) -> ZResult> { let iter = self.documents_fields_counts.iter(reader)?; @@ -89,7 +89,7 @@ impl Iterator for DocumentFieldsCountsIter<'_> { let attr = SchemaAttr(key.attr.get()); Some(Ok((attr, count))) } - Some(Err(e)) => Some(Err(e.into())), + Some(Err(e)) => Some(Err(e)), None => None, } } @@ -113,7 +113,7 @@ impl Iterator for DocumentsIdsIter<'_> { return Some(Ok(document_id)); } } - Err(e) => return Some(Err(e.into())), + Err(e) => return Some(Err(e)), } } None @@ -134,7 +134,7 @@ impl<'r> Iterator for AllDocumentsFieldsCountsIter<'r> { let attr = SchemaAttr(key.attr.get()); Some(Ok((docid, attr, count))) } - Some(Err(e)) => Some(Err(e.into())), + Some(Err(e)) => Some(Err(e)), None => None, } } diff --git a/meilidb-core/src/store/main.rs b/meilidb-core/src/store/main.rs index 86e638582..6e99ac067 100644 --- a/meilidb-core/src/store/main.rs +++ b/meilidb-core/src/store/main.rs @@ -17,12 +17,12 @@ pub struct Main { } impl Main { - pub fn put_words_fst(&self, writer: &mut zlmdb::RwTxn, fst: &fst::Set) -> ZResult<()> { + pub fn put_words_fst(self, writer: &mut zlmdb::RwTxn, fst: &fst::Set) -> ZResult<()> { let bytes = fst.as_fst().as_bytes(); self.main.put::(writer, WORDS_KEY, bytes) } - pub fn words_fst(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn words_fst(self, reader: &zlmdb::RoTxn) -> ZResult> { match self.main.get::(reader, WORDS_KEY)? { Some(bytes) => { let len = bytes.len(); @@ -34,31 +34,31 @@ impl Main { } } - pub fn put_schema(&self, writer: &mut zlmdb::RwTxn, schema: &Schema) -> ZResult<()> { + pub fn put_schema(self, writer: &mut zlmdb::RwTxn, schema: &Schema) -> ZResult<()> { self.main .put::>(writer, SCHEMA_KEY, schema) } - pub fn schema(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn schema(self, reader: &zlmdb::RoTxn) -> ZResult> { self.main.get::>(reader, SCHEMA_KEY) } - pub fn put_ranked_map(&self, writer: &mut zlmdb::RwTxn, ranked_map: &RankedMap) -> ZResult<()> { + pub fn put_ranked_map(self, writer: &mut zlmdb::RwTxn, ranked_map: &RankedMap) -> ZResult<()> { self.main .put::>(writer, RANKED_MAP_KEY, &ranked_map) } - pub fn ranked_map(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn ranked_map(self, reader: &zlmdb::RoTxn) -> ZResult> { self.main .get::>(reader, RANKED_MAP_KEY) } - pub fn put_synonyms_fst(&self, writer: &mut zlmdb::RwTxn, fst: &fst::Set) -> ZResult<()> { + pub fn put_synonyms_fst(self, writer: &mut zlmdb::RwTxn, fst: &fst::Set) -> ZResult<()> { let bytes = fst.as_fst().as_bytes(); self.main.put::(writer, SYNONYMS_KEY, bytes) } - pub fn synonyms_fst(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn synonyms_fst(self, reader: &zlmdb::RoTxn) -> ZResult> { match self.main.get::(reader, SYNONYMS_KEY)? { Some(bytes) => { let len = bytes.len(); @@ -70,7 +70,7 @@ impl Main { } } - pub fn put_number_of_documents(&self, writer: &mut zlmdb::RwTxn, f: F) -> ZResult + pub fn put_number_of_documents(self, writer: &mut zlmdb::RwTxn, f: F) -> ZResult where F: Fn(u64) -> u64, { @@ -80,7 +80,7 @@ impl Main { Ok(new) } - pub fn number_of_documents(&self, reader: &zlmdb::RoTxn) -> ZResult { + pub fn number_of_documents(self, reader: &zlmdb::RoTxn) -> ZResult { match self .main .get::>(reader, NUMBER_OF_DOCUMENTS_KEY)? @@ -90,12 +90,12 @@ impl Main { } } - pub fn put_customs(&self, writer: &mut zlmdb::RwTxn, customs: &[u8]) -> ZResult<()> { + pub fn put_customs(self, writer: &mut zlmdb::RwTxn, customs: &[u8]) -> ZResult<()> { self.main .put::(writer, CUSTOMS_KEY, customs) } - pub fn customs<'txn>(&self, reader: &'txn zlmdb::RoTxn) -> ZResult> { + pub fn customs<'txn>(self, reader: &'txn zlmdb::RoTxn) -> ZResult> { self.main.get::(reader, CUSTOMS_KEY) } } diff --git a/meilidb-core/src/store/mod.rs b/meilidb-core/src/store/mod.rs index 11c1447eb..68170e64e 100644 --- a/meilidb-core/src/store/mod.rs +++ b/meilidb-core/src/store/mod.rs @@ -106,7 +106,7 @@ impl Index { let attributes = match attributes { Some(attributes) => attributes - .into_iter() + .iter() .map(|name| schema.attribute(name)) .collect(), None => None, diff --git a/meilidb-core/src/store/postings_lists.rs b/meilidb-core/src/store/postings_lists.rs index 041c2319b..8835a504a 100644 --- a/meilidb-core/src/store/postings_lists.rs +++ b/meilidb-core/src/store/postings_lists.rs @@ -11,7 +11,7 @@ pub struct PostingsLists { impl PostingsLists { pub fn put_postings_list( - &self, + self, writer: &mut zlmdb::RwTxn, word: &[u8], words_indexes: &Set, @@ -19,12 +19,12 @@ impl PostingsLists { self.postings_lists.put(writer, word, words_indexes) } - pub fn del_postings_list(&self, writer: &mut zlmdb::RwTxn, word: &[u8]) -> ZResult { + pub fn del_postings_list(self, writer: &mut zlmdb::RwTxn, word: &[u8]) -> ZResult { self.postings_lists.delete(writer, word) } pub fn postings_list<'txn>( - &self, + self, reader: &'txn zlmdb::RoTxn, word: &[u8], ) -> ZResult>>> { diff --git a/meilidb-core/src/store/synonyms.rs b/meilidb-core/src/store/synonyms.rs index 1ddaae9e2..b8002d464 100644 --- a/meilidb-core/src/store/synonyms.rs +++ b/meilidb-core/src/store/synonyms.rs @@ -9,7 +9,7 @@ pub struct Synonyms { impl Synonyms { pub fn put_synonyms( - &self, + self, writer: &mut zlmdb::RwTxn, word: &[u8], synonyms: &fst::Set, @@ -18,11 +18,11 @@ impl Synonyms { self.synonyms.put(writer, word, bytes) } - pub fn del_synonyms(&self, writer: &mut zlmdb::RwTxn, word: &[u8]) -> ZResult { + pub fn del_synonyms(self, writer: &mut zlmdb::RwTxn, word: &[u8]) -> ZResult { self.synonyms.delete(writer, word) } - pub fn synonyms(&self, reader: &zlmdb::RoTxn, word: &[u8]) -> ZResult> { + pub fn synonyms(self, reader: &zlmdb::RoTxn, word: &[u8]) -> ZResult> { match self.synonyms.get(reader, word)? { Some(bytes) => { let len = bytes.len(); diff --git a/meilidb-core/src/store/updates.rs b/meilidb-core/src/store/updates.rs index 7bc195895..8afe95e0d 100644 --- a/meilidb-core/src/store/updates.rs +++ b/meilidb-core/src/store/updates.rs @@ -36,7 +36,7 @@ pub struct Updates { impl Updates { // TODO do not trigger deserialize if possible - pub fn last_update_id(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn last_update_id(self, reader: &zlmdb::RoTxn) -> ZResult> { match self.updates.last(reader)? { Some((key, data)) => Ok(Some((key.get(), data))), None => Ok(None), @@ -44,7 +44,7 @@ impl Updates { } // TODO do not trigger deserialize if possible - fn first_update_id(&self, reader: &zlmdb::RoTxn) -> ZResult> { + fn first_update_id(self, reader: &zlmdb::RoTxn) -> ZResult> { match self.updates.first(reader)? { Some((key, data)) => Ok(Some((key.get(), data))), None => Ok(None), @@ -52,13 +52,13 @@ impl Updates { } // TODO do not trigger deserialize if possible - pub fn contains(&self, reader: &zlmdb::RoTxn, update_id: u64) -> ZResult { + pub fn contains(self, reader: &zlmdb::RoTxn, update_id: u64) -> ZResult { let update_id = BEU64::new(update_id); self.updates.get(reader, &update_id).map(|v| v.is_some()) } pub fn put_update( - &self, + self, writer: &mut zlmdb::RwTxn, update_id: u64, update: &Update, @@ -68,7 +68,7 @@ impl Updates { self.updates.put(writer, &update_id, update) } - pub fn pop_front(&self, writer: &mut zlmdb::RwTxn) -> ZResult> { + pub fn pop_front(self, writer: &mut zlmdb::RwTxn) -> ZResult> { match self.first_update_id(writer)? { Some((update_id, update)) => { let key = BEU64::new(update_id); diff --git a/meilidb-core/src/store/updates_results.rs b/meilidb-core/src/store/updates_results.rs index f9d28112d..cd3c96075 100644 --- a/meilidb-core/src/store/updates_results.rs +++ b/meilidb-core/src/store/updates_results.rs @@ -9,7 +9,7 @@ pub struct UpdatesResults { } impl UpdatesResults { - pub fn last_update_id(&self, reader: &zlmdb::RoTxn) -> ZResult> { + pub fn last_update_id(self, reader: &zlmdb::RoTxn) -> ZResult> { match self.updates_results.last(reader)? { Some((key, data)) => Ok(Some((key.get(), data))), None => Ok(None), @@ -17,7 +17,7 @@ impl UpdatesResults { } pub fn put_update_result( - &self, + self, writer: &mut zlmdb::RwTxn, update_id: u64, update_result: &UpdateResult, @@ -27,7 +27,7 @@ impl UpdatesResults { } pub fn update_result( - &self, + self, reader: &zlmdb::RoTxn, update_id: u64, ) -> ZResult> { diff --git a/meilidb-core/src/update/schema_update.rs b/meilidb-core/src/update/schema_update.rs index 13fdab507..652ca06dd 100644 --- a/meilidb-core/src/update/schema_update.rs +++ b/meilidb-core/src/update/schema_update.rs @@ -7,7 +7,7 @@ pub fn apply_schema_update( main_store: store::Main, new_schema: &Schema, ) -> MResult<()> { - if let Some(_) = main_store.schema(writer)? { + if main_store.schema(writer)?.is_some() { return Err(UnsupportedOperation::SchemaAlreadyExists.into()); } diff --git a/meilidb-tokenizer/src/lib.rs b/meilidb-tokenizer/src/lib.rs index bb6002fe1..106d0f91f 100644 --- a/meilidb-tokenizer/src/lib.rs +++ b/meilidb-tokenizer/src/lib.rs @@ -176,7 +176,7 @@ where let current = iter.next().map(|s| Tokenizer::new(s).peekable()); SeqTokenizer { inner: iter, - current: current, + current, word_offset: 0, char_offset: 0, }