1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::simple::search_index::SearchIndex;
// -----------------------------------------------------------------------------
impl<K: Ord> SearchIndex<K> {
// -------------------------------------------------------------------------
//
/// Returns the special keyword that will return all keys (or records) in
/// the search index.
///
/// A _dump keyword_ should be selected so that it's difficult for a user
/// inadvertently trigger this behaviour. It might be a good idea to turn
/// this feature off for extremely large search indexes.
///
/// This keyword is helpful for the [Select2](https://select2.org/) jQuery
/// plug-in, where returning all keys is the desirable behaviour when the
/// search string is empty. It can also be used for fully populating a
/// [\<datalist\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist)
/// element, and potentially other things.
///
/// The default value of `null` is probably fine, but it's configurable and
/// it can be turned off altogether. For more information on the setting the
/// `dump_keyword` for a `SearchIndex` type see: [`SearchIndexBuilder`].
///
/// [`SearchIndexBuilder`]: struct.SearchIndexBuilder.html#method.dump_keyword
///
/// Basic usage:
///
/// ```rust
/// # use indicium::simple::SearchIndex;
/// # let mut search_index: SearchIndex<usize> = SearchIndex::default();
/// assert_eq!(search_index.dump_keyword(), Some("\0"));
/// ```
///
/// The intended usage of `dump_keyword` is retrieve a full listing of all
/// records registered in the search index. Example usage:
///
/// ```rust
/// # use indicium::simple::{AutocompleteType, Indexable, SearchIndex, SearchIndexBuilder};
/// # use pretty_assertions::assert_eq;
/// #
/// # let mut search_index: SearchIndex<usize> =
/// # SearchIndexBuilder::default()
/// # .autocomplete_type(AutocompleteType::Global)
/// # .exclude_keywords(None)
/// # .build();
/// #
/// # struct MyType { text: String }
/// #
/// # impl From<&str> for MyType {
/// # fn from(string: &str) -> Self {
/// # MyType { text: string.to_string() }
/// # }
/// # }
/// #
/// # impl Indexable for MyType {
/// # fn strings(&self) -> Vec<String> {
/// # vec![self.text.clone()]
/// # }
/// # }
/// #
/// # search_index.insert(&0, &MyType::from("apple"));
/// # search_index.insert(&1, &MyType::from("ball"));
/// # search_index.insert(&2, &MyType::from("bath"));
/// # search_index.insert(&3, &MyType::from("bird"));
/// # search_index.insert(&4, &MyType::from("birthday"));
/// # search_index.insert(&5, &MyType::from("red"));
/// # search_index.insert(&6, &MyType::from("truck"));
/// #
/// if let Some(dump_keyword) = search_index.dump_keyword() {
/// assert_eq!(
/// search_index.search(&dump_keyword),
/// [&0, &1, &2, &3, &4, &5, &6]
/// );
/// }
/// ```
#[must_use]
pub fn dump_keyword(&self) -> Option<&str> {
self.dump_keyword.as_ref().map(kstring::KStringBase::as_str)
} // fn
} // impl