Struct indicium::simple::SearchIndexBuilder
source · pub struct SearchIndexBuilder<K> { /* private fields */ }
Expand description
The builder pattern
can be used to customize your search index. Use
SearchIndexBuilder::default()
to start the builder chain, and .build()
to finish it.
If you’re in a hurry, you can instantiate your search index with
SearchIndex::default()
instead.
Implementations§
source§impl<K: Clone + Ord> SearchIndexBuilder<K>
impl<K: Clone + Ord> SearchIndexBuilder<K>
sourcepub const fn search_type(self, search_type: SearchType) -> Self
pub const fn search_type(self, search_type: SearchType) -> Self
Search type (or logical conjuction). Used to determine how to connect
search results for each keyword. See SearchType
for more
information.
Default: SearchType::Live
sourcepub const fn autocomplete_type(
self,
autocomplete_type: AutocompleteType
) -> Self
pub const fn autocomplete_type( self, autocomplete_type: AutocompleteType ) -> Self
Autocomplete type (or keyword scope). Used to determine if or how to
filtering keyword results for autocompletion. See AutocompleteType
for more information.
Default: AutocompleteType::Context
sourcepub const fn strsim_metric(self, strsim_metric: Option<StrsimMetric>) -> Self
pub const fn strsim_metric(self, strsim_metric: Option<StrsimMetric>) -> Self
String similarity metric type from Danny Guo’s
strsim crate. Used for fuzzy matching
user’s keywords when no exact matches were found. See StrsimMetric
for
more information.
Default: StrsimMetric::Levenshtein
sourcepub const fn fuzzy_length(self, fuzzy_length: usize) -> Self
pub const fn fuzzy_length(self, fuzzy_length: usize) -> Self
String’s minimum length (in chars or codepoints) to use “approximate string matching” or “fuzzy matching.”
§Examples
Example | User Keyword | Minimum Length | Index Keyword Must Start With… |
---|---|---|---|
1 | Supercalifragilisticexpialidocious | 2 | Su |
2 | Antidisestablishmentarianism | 4 | Anti |
3 | Pseudopseudohypoparathyroidism | 0 |
-
In example 1, since the length is set to
2
, the user’s keyword will only be fuzzy matched against keywords in the search index that begin withsu
. -
In example 2, since the length is set to
4
, the user’s keyword will only be fuzzy matched against keywords in the search index that begin withanti
. -
In example 3, since the length is set to
0
, the user’s keyword will be fuzzy matched against every keyword in the search index. This is OK (or even desirable) if the search index is small, however, this will be crippling slow on very large search indicies.
Default: 3
characters
sourcepub const fn fuzzy_minimum_score(self, fuzzy_minimum_score: f64) -> Self
pub const fn fuzzy_minimum_score(self, fuzzy_minimum_score: f64) -> Self
Keyword’s minimum score to be used as a possible fuzzy match. Must be a value between 0.0 and 1.0 (inclusive), where 1.0 means the strings are the same.
When there aren’t many good possible matches for a user’s keyword, the quality of the suggestions and substitutions can become very poor. The minimum score helps ensure the suggestion and subtitutions are reasonable.
If there are no reasonable suggestions or subsitutions, nothing will be returned to the user.
Default: 0.3
sourcepub fn split_pattern(self, split_pattern: Option<Vec<char>>) -> Self
pub fn split_pattern(self, split_pattern: Option<Vec<char>>) -> Self
Characters used to split strings into keywords.
Default: [ tab
, new line
, carrier return
, space
, !
, "
,
&
, (
, )
, *
, +
, ,
, -
, .
, /
, :
, ;
, <
, =
, >
,
?
, [
, \
, ]
, ^
, '
, {
, |
, }
, ~
,
, ¡
, «
, »
,
¿
, ×
, ÷
, ˆ
, ‘
, ’
, “
, ”
, „
, ‹
, ›
]
sourcepub const fn case_sensitive(self, case_sensitive: bool) -> Self
pub const fn case_sensitive(self, case_sensitive: bool) -> Self
Indicates whether the search index is case sensitive or not. If set to false (case insensitive), all keywords will be normalized to lower case.
Default: false
sourcepub const fn min_keyword_len(self, minimum_keyword_length: usize) -> Self
pub const fn min_keyword_len(self, minimum_keyword_length: usize) -> Self
Minimum keyword length (in chars or codepoints) to be indexed. If the keyword is shorter the keyword will not be indexed.
Default: 1
sourcepub const fn max_keyword_len(self, maximum_keyword_length: usize) -> Self
pub const fn max_keyword_len(self, maximum_keyword_length: usize) -> Self
Maximum keyword length (in chars or codepoints) to be indexed. If the keyword is longer the keyword will not be indexed.
Default: 24
sourcepub const fn max_string_len(self, maximum_string_length: Option<usize>) -> Self
pub const fn max_string_len(self, maximum_string_length: Option<usize>) -> Self
Maximum string length (in chars or codepoints) to be indexed. If set, Indicium will index the record’s full field text & whole strings as a single keyword for autocompletion purposes.
Default: Some(24)
sourcepub fn exclude_keywords(self, exclude_keywords: Option<Vec<String>>) -> Self
pub fn exclude_keywords(self, exclude_keywords: Option<Vec<String>>) -> Self
List of keywords that should not be indexed. It might be a good idea to
exclude minor words - short conjunctions, articles, and short
prepositions from your search index. For example, words such as and
,
as
, a
, as
, at
, etc. See also: the profile
utility method.
sourcepub const fn max_autocomplete_options(
self,
maximum_autocomplete_options: usize
) -> Self
pub const fn max_autocomplete_options( self, maximum_autocomplete_options: usize ) -> Self
Maximum number of auto-complete options to return. This setting can be overidden by some function arguments.
Default: 5
sourcepub const fn max_search_results(self, maximum_search_results: usize) -> Self
pub const fn max_search_results(self, maximum_search_results: usize) -> Self
Maximum number of search results to return. This setting can be overidden by some function arguments.
Default: 100
sourcepub const fn max_keys_per_keyword(self, maximum_keys_per_keyword: usize) -> Self
pub const fn max_keys_per_keyword(self, maximum_keys_per_keyword: usize) -> Self
Maximum number of keys per keyword. If there are too many records
attached to a single keyword, performance can begin to degrade. This
setting limits the number of keys that may be attached to a keyword. See
also: the exclude_keywords
list and the profile
method.
Default: 40_960
sourcepub fn dump_keyword(self, dump_keyword: Option<String>) -> Self
pub fn dump_keyword(self, dump_keyword: Option<String>) -> Self
A special keyword that will return or “dump” all keys (or records) in
the search index. This is helpful for the Select2
module, where it
should be returning all records if the search string is empty.
Default: Some("\0".to_string())
sourcepub fn build(self) -> SearchIndex<K>
pub fn build(self) -> SearchIndex<K>
Build SearchIndex
from the settings given to the SearchIndexBuilder
.
Trait Implementations§
source§impl<K: Clone + Ord> From<SearchIndex<K>> for SearchIndexBuilder<K>
impl<K: Clone + Ord> From<SearchIndex<K>> for SearchIndexBuilder<K>
source§fn from(search_index: SearchIndex<K>) -> Self
fn from(search_index: SearchIndex<K>) -> Self
Convert to SearchIndexBuilder<K>
struct from SearchIndex<K>
struct.
source§impl<K: Clone + Ord> From<SearchIndexBuilder<K>> for SearchIndex<K>
impl<K: Clone + Ord> From<SearchIndexBuilder<K>> for SearchIndex<K>
source§fn from(search_index: SearchIndexBuilder<K>) -> Self
fn from(search_index: SearchIndexBuilder<K>) -> Self
Convert to SearchIndex<K>
struct from SearchIndexBuilder<K>
struct.