Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
leontoeides committed Feb 8, 2024
1 parent 41a56d3 commit 613939f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Indicium Search
# indicium
[![Docs](https://docs.rs/indicium/badge.svg)](https://docs.rs/indicium)
[![Crates.io](https://img.shields.io/crates/v/indicium.svg?maxAge=2592000)](https://crates.io/crates/indicium)
[![msrv](https://img.shields.io/badge/rustc-1.62.1+-red)](https://blog.rust-lang.org/2023/06/01/Rust-1.62.1.html)

🔎 A simple in-memory search for collections (Vec, HashMap, BTreeMap, etc) and
key-value stores. Features autocompletion.
Expand Down
7 changes: 4 additions & 3 deletions src/simple/autocomplete/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ impl<K: Hash + Ord> SearchIndex<K> {
) -> Vec<&str> {
// If case sensitivity set, leave case intact. Otherwise, normalize
// keyword to lower case:
let keyword = match self.case_sensitive {
true => keyword.to_string(),
false => keyword.to_lowercase(),
let keyword = if self.case_sensitive {
keyword.to_string()
} else {
keyword.to_lowercase()
}; // match

// For debug builds:
Expand Down
26 changes: 13 additions & 13 deletions src/simple/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// [`SearchType`]: enum.SearchType.html
#[must_use]
pub fn search_type(mut self, search_type: SearchType) -> Self {
pub const fn search_type(mut self, search_type: SearchType) -> Self {
self.search_type = search_type;
self
} // fn
Expand All @@ -120,7 +120,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// [`AutocompleteType`]: enum.AutocompleteType.html
#[must_use]
pub fn autocomplete_type(mut self, autocomplete_type: AutocompleteType) -> Self {
pub const fn autocomplete_type(mut self, autocomplete_type: AutocompleteType) -> Self {
self.autocomplete_type = autocomplete_type;
self
} // fn
Expand All @@ -134,7 +134,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// [`StrsimMetric`]: enum.StrsimMetric.html
#[cfg(feature = "strsim")]
pub fn strsim_metric(mut self, strsim_metric: Option<StrsimMetric>) -> Self {
pub const fn strsim_metric(mut self, strsim_metric: Option<StrsimMetric>) -> Self {
self.strsim_metric = strsim_metric;
self
} // fn
Expand All @@ -149,7 +149,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
/// [`EddieMetric`]: enum.EddieMetric.html
#[cfg(feature = "eddie")]
#[must_use]
pub fn eddie_metric(mut self, eddie_metric: Option<EddieMetric>) -> Self {
pub const fn eddie_metric(mut self, eddie_metric: Option<EddieMetric>) -> Self {
self.eddie_metric = eddie_metric;
self
} // fn
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
/// **Default:** `3` characters
#[cfg(any(feature = "eddie", feature = "strsim"))]
#[must_use]
pub fn fuzzy_length(mut self, fuzzy_length: usize) -> Self {
pub const fn fuzzy_length(mut self, fuzzy_length: usize) -> Self {
self.fuzzy_length = fuzzy_length;
self
} // fn
Expand All @@ -201,7 +201,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
/// **Default:** `0.3`
#[cfg(any(feature = "eddie", feature = "strsim"))]
#[must_use]
pub fn fuzzy_minimum_score(mut self, fuzzy_minimum_score: f64) -> Self {
pub const fn fuzzy_minimum_score(mut self, fuzzy_minimum_score: f64) -> Self {
self.fuzzy_minimum_score = fuzzy_minimum_score;
self
} // fn
Expand All @@ -223,7 +223,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `false`
#[must_use]
pub fn case_sensitive(mut self, case_sensitive: bool) -> Self {
pub const fn case_sensitive(mut self, case_sensitive: bool) -> Self {
self.case_sensitive = case_sensitive;
self
} // fn
Expand All @@ -233,7 +233,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `1`
#[must_use]
pub fn min_keyword_len(mut self, minimum_keyword_length: usize) -> Self {
pub const fn min_keyword_len(mut self, minimum_keyword_length: usize) -> Self {
self.minimum_keyword_length = minimum_keyword_length;
self
} // fn
Expand All @@ -243,7 +243,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `24`
#[must_use]
pub fn max_keyword_len(mut self, maximum_keyword_length: usize) -> Self {
pub const fn max_keyword_len(mut self, maximum_keyword_length: usize) -> Self {
self.maximum_keyword_length = maximum_keyword_length;
self
} // fn
Expand All @@ -254,7 +254,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `Some(24)`
#[must_use]
pub fn max_string_len(mut self, maximum_string_length: Option<usize>) -> Self {
pub const fn max_string_len(mut self, maximum_string_length: Option<usize>) -> Self {
self.maximum_string_length = maximum_string_length;
self
} // fn
Expand All @@ -277,7 +277,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `5`
#[must_use]
pub fn max_autocomplete_options(mut self, maximum_autocomplete_options: usize) -> Self {
pub const fn max_autocomplete_options(mut self, maximum_autocomplete_options: usize) -> Self {
self.maximum_autocomplete_options = maximum_autocomplete_options;
self
} // fn
Expand All @@ -287,7 +287,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `100`
#[must_use]
pub fn max_search_results(mut self, maximum_search_results: usize) -> Self {
pub const fn max_search_results(mut self, maximum_search_results: usize) -> Self {
self.maximum_search_results = maximum_search_results;
self
} // fn
Expand All @@ -299,7 +299,7 @@ impl<K: Clone + Ord> SearchIndexBuilder<K> {
///
/// **Default:** `40_960`
#[must_use]
pub fn max_keys_per_keyword(mut self, maximum_keys_per_keyword: usize) -> Self {
pub const fn max_keys_per_keyword(mut self, maximum_keys_per_keyword: usize) -> Self {
self.maximum_keys_per_keyword = maximum_keys_per_keyword;
self
} // fn
Expand Down
15 changes: 7 additions & 8 deletions src/simple/internal/eddie/eddie_global_autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ impl<K: Hash + Ord> SearchIndex<K> {
// Attempt to find the top matches for the user's (partial) keyword
// using the selected string similarity metric defined in the
// `SearchIndex`:
if let Some(eddie_metric) = &self.eddie_metric {
match eddie_metric {
self.eddie_metric.as_ref().map_or_else(
// No string similarity metric was defined in the `SearchIndex`
// settings. Fuzzy string matching effectively turned off.
// Return an empty `Vec` to the caller:
|| vec![],
|eddie_metric| match eddie_metric {
EddieMetric::DamerauLevenshtein => self
.eddie_autocomplete_global_damerau_levenshtein(index_range, user_keyword)
.collect(),
Expand All @@ -80,11 +84,6 @@ impl<K: Hash + Ord> SearchIndex<K> {
.eddie_autocomplete_global_levenshtein(index_range, user_keyword)
.collect(),
} // match
} else {
// No string similarity metric was defined in the `SearchIndex`
// settings. Fuzzy string matching effectively turned off.
// Return an empty `Vec` to the caller:
vec![]
} // if
) // map_or_else
} // fn
} // impl

0 comments on commit 613939f

Please sign in to comment.