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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Stopword management endpoints.
//!
//! Stopwords are terms the engine ignores at index and query time. Reading the
//! list uses the read key; changing it uses the ingest key.
use reqwest::Method;
use crate::client::SearchcraftClient;
use crate::config::Operation;
use crate::error;
impl SearchcraftClient {
/// Gets the stopword list for an index.
///
/// `GET /index/{index_name}/stopwords`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// index does not exist.
pub async fn get_stopwords(&self, index_name: &str) -> error::Result<Vec<String>> {
let path = format!("index/{index_name}/stopwords");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
/// Gets the engine's built-in stopword list for the index's language.
///
/// These are the defaults the index starts from, distinct from the
/// customized list returned by [`get_stopwords`](Self::get_stopwords).
///
/// `GET /index/{index_name}/stopwords/default`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// index does not exist.
pub async fn get_default_stopwords(&self, index_name: &str) -> error::Result<Vec<String>> {
let path = format!("index/{index_name}/stopwords/default");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
/// Adds stopwords to an index.
///
/// `POST /index/{index_name}/stopwords`
///
/// ```no_run
/// # async fn example() -> searchcraft::error::Result<()> {
/// # let client = searchcraft::SearchcraftClient::new("https://x.io", Some("k"), Some("w"))?;
/// client.add_stopwords("products", &["the", "and"]).await?;
/// # Ok(())
/// # }
/// ```
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::NotFound`](crate::Error::NotFound) if the index does not exist.
pub async fn add_stopwords(
&self,
index_name: &str,
stopwords: &[impl AsRef<str>],
) -> error::Result<String> {
let path = format!("index/{index_name}/stopwords");
let body: Vec<&str> = stopwords.iter().map(AsRef::as_ref).collect();
self.transport
.request_data(Method::POST, &path, Operation::Write, Some(&body))
.await
}
/// Removes specific stopwords from an index.
///
/// `DELETE /index/{index_name}/stopwords`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::NotFound`](crate::Error::NotFound) if the index does not exist.
pub async fn delete_stopwords(
&self,
index_name: &str,
stopwords: &[impl AsRef<str>],
) -> error::Result<String> {
let path = format!("index/{index_name}/stopwords");
let body: Vec<&str> = stopwords.iter().map(AsRef::as_ref).collect();
self.transport
.request_data(Method::DELETE, &path, Operation::Write, Some(&body))
.await
}
/// Clears the entire stopword list for an index.
///
/// `DELETE /index/{index_name}/stopwords/all`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::NotFound`](crate::Error::NotFound) if the index does not exist.
pub async fn delete_all_stopwords(&self, index_name: &str) -> error::Result<String> {
let path = format!("index/{index_name}/stopwords/all");
self.transport
.request_data(Method::DELETE, &path, Operation::Write, None::<&()>)
.await
}
}