Skip to content

web search done right

rustup update and fix clippy

Mikkel Denkerc03b249047f3
diff --git a/crates/core/src/config/mod.rs b/crates/core/src/config/mod.rs
index 4a246cf3..9162055a 100644
--- a/crates/core/src/config/mod.rs
+++ b/crates/core/src/config/mod.rs
@@ -82,7 +82,7 @@ impl WarcSource {
}
}
WarcSource::Local(config) => {
- warc_paths = config.names.clone();
+ warc_paths.clone_from(&config.names);
}
WarcSource::S3(config) => {
let bucket = s3::Bucket::new(
diff --git a/crates/core/src/distributed/retry_strategy.rs b/crates/core/src/distributed/retry_strategy.rs
index ccc75a67..cd367814 100644
--- a/crates/core/src/distributed/retry_strategy.rs
+++ b/crates/core/src/distributed/retry_strategy.rs
@@ -3,7 +3,6 @@
* and modified as it seems silly to pull-in a new dependency for a single file.
* */
use rand::Rng;
-use std::iter::Iterator;
use std::time::Duration;
use std::u64::MAX as U64_MAX;
diff --git a/crates/core/src/inverted_index.rs b/crates/core/src/inverted_index.rs
index afa3ca00..150c7a83 100644
--- a/crates/core/src/inverted_index.rs
+++ b/crates/core/src/inverted_index.rs
@@ -796,12 +796,7 @@ mod tests {
use candle_core::Tensor;
use maplit::hashmap;
- use crate::{
- config::CollectorConfig,
- ranking::{Ranker, SignalAggregator},
- searcher::SearchQuery,
- webpage::Html,
- };
+ use crate::{config::CollectorConfig, ranking::Ranker, searcher::SearchQuery, webpage::Html};
use super::*;
diff --git a/crates/core/src/metrics.rs b/crates/core/src/metrics.rs
index dd25551e..3921d70b 100644
--- a/crates/core/src/metrics.rs
+++ b/crates/core/src/metrics.rs
@@ -202,7 +202,6 @@ impl Display for PrometheusGroup {
#[cfg(test)]
mod tests {
- use std::time::{SystemTime, UNIX_EPOCH};
use super::*;
diff --git a/crates/core/src/prehashed.rs b/crates/core/src/prehashed.rs
index b1405cf8..4453d9c9 100644
--- a/crates/core/src/prehashed.rs
+++ b/crates/core/src/prehashed.rs
@@ -14,38 +14,10 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-use std::hash::{BuildHasher, Hash, Hasher};
+use std::hash::Hash;
use serde::{Deserialize, Serialize};
-struct PrehashBuilder {}
-
-impl BuildHasher for PrehashBuilder {
- type Hasher = Prehasher;
-
- fn build_hasher(&self) -> Self::Hasher {
- Prehasher { val: 0 }
- }
-}
-
-struct Prehasher {
- val: u128,
-}
-
-impl Hasher for Prehasher {
- fn finish(&self) -> u64 {
- self.val as u64
- }
-
- fn write(&mut self, _bytes: &[u8]) {
- unimplemented!("This hasher only supports u128")
- }
-
- fn write_u128(&mut self, i: u128) {
- self.val = i;
- }
-}
-
#[derive(Debug, Eq, Clone, Copy, Serialize, Deserialize)]
pub struct Prehashed(pub u128);
diff --git a/crates/core/src/query/mod.rs b/crates/core/src/query/mod.rs
index 5a9bba0a..712f2b1e 100644
--- a/crates/core/src/query/mod.rs
+++ b/crates/core/src/query/mod.rs
@@ -244,12 +244,7 @@ impl tantivy::query::Query for Query {
#[cfg(test)]
mod tests {
- use crate::{
- index::Index,
- rand_words,
- searcher::{LocalSearcher, SearchQuery},
- webpage::Webpage,
- };
+ use crate::{index::Index, rand_words, searcher::LocalSearcher, webpage::Webpage};
use super::*;
diff --git a/crates/core/src/ranking/bitvec_similarity.rs b/crates/core/src/ranking/bitvec_similarity.rs
index 2a98600a..af1d8e01 100644
--- a/crates/core/src/ranking/bitvec_similarity.rs
+++ b/crates/core/src/ranking/bitvec_similarity.rs
@@ -163,7 +163,6 @@ impl BitVec {
#[cfg(test)]
mod tests {
use super::*;
- use itertools::Itertools;
use std::iter::repeat;
fn into_ranks(a: &[bool]) -> Vec<u64> {
diff --git a/crates/core/src/schema/mod.rs b/crates/core/src/schema/mod.rs
index 1a14d767..b5021c18 100644
--- a/crates/core/src/schema/mod.rs
+++ b/crates/core/src/schema/mod.rs
@@ -48,7 +48,7 @@ impl Field {
}
let _field_id = field_id - FastFieldEnum::num_variants();
- return None;
+ None
}
#[inline]
diff --git a/crates/core/src/schema/text_field.rs b/crates/core/src/schema/text_field.rs
index a69cbfd0..0bb60d5f 100644
--- a/crates/core/src/schema/text_field.rs
+++ b/crates/core/src/schema/text_field.rs
@@ -297,7 +297,7 @@ impl TextField for Title {
cache
.pretokenize_title()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?,
);
@@ -361,7 +361,7 @@ impl TextField for StemmedTitle {
let title = cache
.pretokenize_title()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?;
let mut tokens = title.tokens.clone();
stem_tokens(&mut tokens, html.lang().copied().unwrap_or(Lang::Eng));
@@ -441,7 +441,7 @@ impl TextField for AllBody {
let all_text = cache
.pretokenize_all_text()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?;
doc.add_pre_tokenized_text(self.tantivy_field(schema), all_text.clone());
@@ -900,7 +900,7 @@ impl TextField for TitleIfHomepage {
let title = cache
.pretokenize_title()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?;
if html.is_homepage() {
@@ -1157,7 +1157,7 @@ impl TextField for TitleBigrams {
let title = cache
.pretokenize_title()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?;
doc.add_text(self.tantivy_field(schema), title.text.clone());
@@ -1246,7 +1246,7 @@ impl TextField for TitleTrigrams {
let title = cache
.pretokenize_title()
.as_ref()
- .map(Clone::clone)
+ .cloned()
.map_err(|e| anyhow::anyhow!("{}", e))?;
doc.add_text(self.tantivy_field(schema), title.text.clone());
diff --git a/crates/core/src/search_prettifier/mod.rs b/crates/core/src/search_prettifier/mod.rs
index dbaa49fa..1d4e0c45 100644
--- a/crates/core/src/search_prettifier/mod.rs
+++ b/crates/core/src/search_prettifier/mod.rs
@@ -233,7 +233,7 @@ pub enum DisplayedSidebar {
#[cfg(test)]
mod tests {
use super::*;
- use chrono::{DateTime, Utc};
+ use chrono::DateTime;
#[test]
fn prettify_date_in_hours() {
diff --git a/crates/core/src/warc.rs b/crates/core/src/warc.rs
index 7035ce0f..757c656d 100644
--- a/crates/core/src/warc.rs
+++ b/crates/core/src/warc.rs
@@ -670,10 +670,8 @@ impl Default for WarcWriter {
mod tests {
use super::*;
use core::panic;
- use flate2::write::GzEncoder;
- use flate2::Compression;
+
use proptest::prelude::*;
- use std::io::Write;
#[test]
fn it_works() {
diff --git a/crates/core/src/web_spell/spell_checker.rs b/crates/core/src/web_spell/spell_checker.rs
index 6a9a308e..b63289dd 100644
--- a/crates/core/src/web_spell/spell_checker.rs
+++ b/crates/core/src/web_spell/spell_checker.rs
@@ -91,7 +91,7 @@ impl LangSpellChecker {
continue;
}
- context[term_idx] = candidate.clone();
+ context[term_idx].clone_from(candidate);
let log_prob = self.lm_logprob(term_idx, &context);
diff --git a/crates/core/src/web_spell/trainer.rs b/crates/core/src/web_spell/trainer.rs
index 91865b99..7cc3c1db 100644
--- a/crates/core/src/web_spell/trainer.rs
+++ b/crates/core/src/web_spell/trainer.rs
@@ -166,8 +166,7 @@ impl SecondTrainer {
.chain(vec![&term])
.map(|t| {
let mut words = context.clone();
- words[1] = t.clone();
-
+ words[1].clone_from(t);
(self.lm_model.freq(&words), t)
})
.max_by(|(a, _), (b, _)| a.cmp(b))
diff --git a/crates/core/src/webgraph/store.rs b/crates/core/src/webgraph/store.rs
index 7db3ad5d..d9600dc0 100644
--- a/crates/core/src/webgraph/store.rs
+++ b/crates/core/src/webgraph/store.rs
@@ -647,8 +647,6 @@ impl EdgeStore {
#[cfg(test)]
mod tests {
- use crate::webgraph::FullNodeID;
-
use super::*;
#[test]
diff --git a/crates/core/src/webpage/html/into_tantivy.rs b/crates/core/src/webpage/html/into_tantivy.rs
index 383da490..6cd3418f 100644
--- a/crates/core/src/webpage/html/into_tantivy.rs
+++ b/crates/core/src/webpage/html/into_tantivy.rs
@@ -135,7 +135,7 @@ impl Html {
.root_domain()
.unwrap_or_default()
.find('.')
- .map(|index| &domain[..ceil_char_boundary(&domain, index).min(domain.len())])
+ .map(|index| &domain[..ceil_char_boundary(domain, index).min(domain.len())])
.unwrap_or_default()
.to_string()
}
diff --git a/crates/core/src/webpage/html/mod.rs b/crates/core/src/webpage/html/mod.rs
index b7faf546..2dc56a52 100644
--- a/crates/core/src/webpage/html/mod.rs
+++ b/crates/core/src/webpage/html/mod.rs
@@ -476,10 +476,7 @@ mod tests {
use std::collections::HashMap;
- use crate::{
- schema::create_schema,
- webpage::{url_ext::UrlExt, Link},
- };
+ use crate::{schema::create_schema, webpage::Link};
use super::*;
diff --git a/crates/core/src/webpage/schema_org/microdata.rs b/crates/core/src/webpage/schema_org/microdata.rs
index 328a8ca2..15cb25fa 100644
--- a/crates/core/src/webpage/schema_org/microdata.rs
+++ b/crates/core/src/webpage/schema_org/microdata.rs
@@ -345,8 +345,6 @@ mod tests {
use kuchiki::traits::TendrilSink;
use maplit::hashmap;
- use crate::webpage::schema_org::RawOneOrMany;
-
use super::*;
#[test]
@@ -613,13 +611,13 @@ mod tests {
<img src="mexico-beach.jpg"
alt="Sunny, sandy beach."
itemprop="contentUrl" />
-
+
By <span itemprop="author">Jane Doe</span>
Photographed in
<span itemprop="contentLocation">Puerto Vallarta, Mexico</span>
Date uploaded:
<meta itemprop="datePublished" content="2008-01-25">Jan 25, 2008
-
+
<span itemprop="description">I took this picture while on vacation last year.</span>
</div>
</html>
@@ -651,7 +649,7 @@ mod tests {
<div itemscope itemtype="https://schema.org/Person">
<span itemprop="name">Jane Doe</span>
<img src="janedoe.jpg" itemprop="image" alt="Photo of Jane Doe"/>
-
+
<span itemprop="jobTitle">Professor</span>
<div itemprop="address" itemscope itemtype="https://schema.org/PostalAddress">
<span itemprop="streetAddress">
@@ -665,10 +663,10 @@ mod tests {
<span itemprop="telephone">(425) 123-4567</span>
<a href="mailto:[email protected]" itemprop="email">
-
+
Jane's home page:
<a href="http://www.janedoe.com" itemprop="url">janedoe.com</a>
-
+
Graduate students:
<a href="http://www.xyz.edu/students/alicejones.html" itemprop="colleague">
Alice Jones</a>
diff --git a/crates/kuchiki/src/parser.rs b/crates/kuchiki/src/parser.rs
index a69447c6..5ea5900b 100644
--- a/crates/kuchiki/src/parser.rs
+++ b/crates/kuchiki/src/parser.rs
@@ -1,6 +1,6 @@
use html5ever::tendril::StrTendril;
use html5ever::tree_builder::{ElementFlags, NodeOrText, QuirksMode, TreeSink};
-use html5ever::{self, Attribute, ExpandedName, QualName};
+use html5ever::{Attribute, ExpandedName, QualName};
use std::borrow::Cow;
use crate::attributes;
diff --git a/crates/kuchiki/src/select.rs b/crates/kuchiki/src/select.rs
index 05cde0e5..12942df0 100644
--- a/crates/kuchiki/src/select.rs
+++ b/crates/kuchiki/src/select.rs
@@ -3,7 +3,7 @@ use crate::iter::{NodeIterator, Select};
use crate::node_data_ref::NodeDataRef;
use crate::tree::{ElementData, Node, NodeData, NodeRef};
use crate::{Error, Result};
-use cssparser::{self, CowRcStr, ParseError, SourceLocation, ToCss};
+use cssparser::{CowRcStr, ParseError, SourceLocation, ToCss};
use html5ever::{LocalName, Namespace};
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
use selectors::context::QuirksMode;
@@ -11,7 +11,7 @@ use selectors::parser::SelectorParseErrorKind;
use selectors::parser::{
NonTSPseudoClass, Parser, Selector as GenericSelector, SelectorImpl, SelectorList,
};
-use selectors::{self, matching, OpaqueElement};
+use selectors::{matching, OpaqueElement};
use std::fmt;
/// The definition of whitespace per CSS Selectors Level 3 § 4.
diff --git a/crates/optics/src/lib.rs b/crates/optics/src/lib.rs
index 92bc00eb..331d4b34 100644
--- a/crates/optics/src/lib.rs
+++ b/crates/optics/src/lib.rs
@@ -20,7 +20,6 @@ mod lexer;
use ast::RankingCoeff;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
-use std::convert::TryFrom;
use std::fmt::Display;
use thiserror::Error;
use utoipa::ToSchema;
@@ -509,7 +508,7 @@ impl HostRankings {
#[cfg(test)]
mod tests {
- use crate::ast::{RankingCoeff, RankingTarget};
+ use crate::ast::RankingTarget;
use super::*;
#[test]
diff --git a/crates/zimba/src/wiki.rs b/crates/zimba/src/wiki.rs
index d063998f..54b41433 100644
--- a/crates/zimba/src/wiki.rs
+++ b/crates/zimba/src/wiki.rs
@@ -122,7 +122,7 @@ impl<'a> Iterator for ArticleIterator<'a> {
let mut title = article_ref.title;
if title.is_empty() {
- title = article_ref.url.clone();
+ title.clone_from(&article_ref.url);
}
let article = Article {