remove useless SmallVec dependency, and go insane because it was used with a zero sized array for storage

This commit is contained in:
Milim 2024-08-15 09:02:37 +02:00
parent 23799eeb9e
commit 215a928eb4
No known key found for this signature in database
4 changed files with 2 additions and 167 deletions

4
Cargo.lock generated
View file

@ -2919,9 +2919,6 @@ name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
dependencies = [
"serde",
]
[[package]]
name = "socket2"
@ -3761,7 +3758,6 @@ dependencies = [
"scraper",
"serde",
"serde_json",
"smallvec 1.13.2",
"stop-words",
"tempfile",
"thesaurus",

View file

@ -40,10 +40,6 @@ error-stack = { version = "0.4.0", default-features = false, features = [
] }
async-trait = { version = "0.1.80", default-features = false }
regex = { version = "1.9.4", features = ["perf"], default-features = false }
smallvec = { version = "1.13.1", features = [
"union",
"serde",
], default-features = false }
futures = { version = "0.3.30", default-features = false, features = ["alloc"] }
async-once-cell = { version = "0.5.3", default-features = false }
mini-moka = { version = "0.10", default-features = false, features = [

View file

@ -3,7 +3,7 @@
use super::engine_models::EngineError;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
#[cfg(any(
feature = "use-synonyms-search",
feature = "use-non-static-synonyms-search"
@ -23,7 +23,7 @@ pub struct SearchResult {
/// The description of the search result.
pub description: String,
/// The names of the upstream engines from which this results were provided.
pub engine: SmallVec<[String; 0]>,
pub engine: Vec<String>,
/// The td-tdf score of the result in regards to the title, url and description and the user's query
pub relevance_score: f32,
}

View file

@ -227,160 +227,3 @@ fn sort_search_results(results: &mut [SearchResult]) {
.unwrap_or(Ordering::Less)
})
}
#[cfg(test)]
mod tests {
use super::*;
use smallvec::smallvec;
use std::io::Write;
use tempfile::NamedTempFile;
#[tokio::test]
async fn test_filter_with_lists() -> Result<(), Box<dyn std::error::Error>> {
// Create a map of search results to filter
let mut map_to_be_filtered = Vec::new();
map_to_be_filtered.push((
"https://www.example.com".to_owned(),
SearchResult {
title: "Example Domain".to_owned(),
url: "https://www.example.com".to_owned(),
description: "This domain is for use in illustrative examples in documents."
.to_owned(),
relevance_score: 0.0,
engine: smallvec!["Google".to_owned(), "Bing".to_owned()],
},
));
map_to_be_filtered.push((
"https://www.rust-lang.org/".to_owned(),
SearchResult {
title: "Rust Programming Language".to_owned(),
url: "https://www.rust-lang.org/".to_owned(),
description: "A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.".to_owned(),
engine: smallvec!["Google".to_owned(), "DuckDuckGo".to_owned()],
relevance_score:0.0
},)
);
// Create a temporary file with regex patterns
let mut file = NamedTempFile::new()?;
writeln!(file, "example")?;
writeln!(file, "rust")?;
file.flush()?;
let mut resultant_map = Vec::new();
filter_with_lists(
&mut map_to_be_filtered,
&mut resultant_map,
file.path().to_str().unwrap(),
)
.await?;
assert_eq!(resultant_map.len(), 2);
assert!(resultant_map
.iter()
.any(|(key, _)| key == "https://www.example.com"));
assert!(resultant_map
.iter()
.any(|(key, _)| key == "https://www.rust-lang.org/"));
assert_eq!(map_to_be_filtered.len(), 0);
Ok(())
}
#[tokio::test]
async fn test_filter_with_lists_wildcard() -> Result<(), Box<dyn std::error::Error>> {
let mut map_to_be_filtered = Vec::new();
map_to_be_filtered.push((
"https://www.example.com".to_owned(),
SearchResult {
title: "Example Domain".to_owned(),
url: "https://www.example.com".to_owned(),
description: "This domain is for use in illustrative examples in documents."
.to_owned(),
engine: smallvec!["Google".to_owned(), "Bing".to_owned()],
relevance_score: 0.0,
},
));
map_to_be_filtered.push((
"https://www.rust-lang.org/".to_owned(),
SearchResult {
title: "Rust Programming Language".to_owned(),
url: "https://www.rust-lang.org/".to_owned(),
description: "A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.".to_owned(),
engine: smallvec!["Google".to_owned(), "DuckDuckGo".to_owned()],
relevance_score:0.0
},
));
// Create a temporary file with a regex pattern containing a wildcard
let mut file = NamedTempFile::new()?;
writeln!(file, "ex.*le")?;
file.flush()?;
let mut resultant_map = Vec::new();
filter_with_lists(
&mut map_to_be_filtered,
&mut resultant_map,
file.path().to_str().unwrap(),
)
.await?;
assert_eq!(resultant_map.len(), 1);
assert!(resultant_map
.iter()
.any(|(key, _)| key == "https://www.example.com"));
assert_eq!(map_to_be_filtered.len(), 1);
assert!(map_to_be_filtered
.iter()
.any(|(key, _)| key == "https://www.rust-lang.org/"));
Ok(())
}
#[tokio::test]
async fn test_filter_with_lists_file_not_found() {
let mut map_to_be_filtered = Vec::new();
let mut resultant_map = Vec::new();
// Call the `filter_with_lists` function with a non-existent file path
let result = filter_with_lists(
&mut map_to_be_filtered,
&mut resultant_map,
"non-existent-file.txt",
);
assert!(result.await.is_err());
}
#[tokio::test]
async fn test_filter_with_lists_invalid_regex() {
let mut map_to_be_filtered = Vec::new();
map_to_be_filtered.push((
"https://www.example.com".to_owned(),
SearchResult {
title: "Example Domain".to_owned(),
url: "https://www.example.com".to_owned(),
description: "This domain is for use in illustrative examples in documents."
.to_owned(),
engine: smallvec!["Google".to_owned(), "Bing".to_owned()],
relevance_score: 0.0,
},
));
let mut resultant_map = Vec::new();
// Create a temporary file with an invalid regex pattern
let mut file = NamedTempFile::new().unwrap();
writeln!(file, "example(").unwrap();
file.flush().unwrap();
let result = filter_with_lists(
&mut map_to_be_filtered,
&mut resultant_map,
file.path().to_str().unwrap(),
);
assert!(result.await.is_err());
}
}