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>

source

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

source

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

source

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

source

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
ExampleUser KeywordMinimum LengthIndex Keyword Must Start With…
1Supercalifragilisticexpialidocious2Su
2Antidisestablishmentarianism4Anti
3Pseudopseudohypoparathyroidism0
  • 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 with su.

  • 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 with anti.

  • 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

source

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

source

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, !, ", &, (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, [, \, ], ^, ', {, |, }, ~, , ¡, «, », ¿, ×, ÷, ˆ, , , , , , , ]

source

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

source

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

source

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

source

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)

source

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.

source

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

source

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

source

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

source

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())

source

pub fn build(self) -> SearchIndex<K>

Build SearchIndex from the settings given to the SearchIndexBuilder.

Trait Implementations§

source§

impl<K: Clone + Ord> Default for SearchIndexBuilder<K>

source§

fn default() -> Self

Initialize SearchIndexBuilder with default settings.

source§

impl<K: Clone + Ord> From<SearchIndex<K>> for SearchIndexBuilder<K>

source§

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>

source§

fn from(search_index: SearchIndexBuilder<K>) -> Self

Convert to SearchIndex<K> struct from SearchIndexBuilder<K> struct.

Auto Trait Implementations§

§

impl<K> Freeze for SearchIndexBuilder<K>

§

impl<K> RefUnwindSafe for SearchIndexBuilder<K>
where K: RefUnwindSafe,

§

impl<K> Send for SearchIndexBuilder<K>
where K: Send,

§

impl<K> Sync for SearchIndexBuilder<K>
where K: Sync,

§

impl<K> Unpin for SearchIndexBuilder<K>

§

impl<K> UnwindSafe for SearchIndexBuilder<K>
where K: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more