Skip to main content

hey_sdk/generated/services/
search.rs

1// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
4
5use crate::client::Client;
6use crate::error::Error;
7use crate::generated::routes;
8use crate::generated::types::*;
9use crate::pagination::Page;
10
11/// Optional query parameters for `AdvancedSearch`.
12#[derive(Debug, Clone, Default, PartialEq)]
13pub struct AdvancedSearchParams {
14    pub q: Option<String>,
15    pub page: Option<String>,
16    pub refine_from: Option<String>,
17    pub refine_to: Option<String>,
18    pub refine_subject: Option<String>,
19    pub refine_exact_phrase: Option<String>,
20    pub refine_required: Option<String>,
21    pub refine_any: Option<String>,
22    pub refine_none: Option<String>,
23    pub refine_date: Option<String>,
24    pub refine_in: Option<String>,
25    pub refine_label: Option<String>,
26    pub refine_attachment: Option<String>,
27}
28
29pub struct Search<'a> {
30    client: &'a Client,
31}
32
33impl<'a> Search<'a> {
34    pub(crate) fn new(client: &'a Client) -> Self {
35        Self { client }
36    }
37
38    /// The client this service sends through.
39    pub fn client(&self) -> &'a Client {
40        self.client
41    }
42
43    /// Get the options the advanced search refine form offers.
44    ///
45    /// Advanced search: message matches grouped by topic as the search page shows them —
46    /// the topic, its posting id, and the matching entries as summaries (no bodies; read a
47    /// message with GetMessage). Refinements are the same query parameters the page uses.
48    /// The next page, if any, is a Link header.
49    pub async fn advanced(
50        &self,
51        params: &AdvancedSearchParams,
52    ) -> Result<Page<AdvancedSearchResponseContent>, Error> {
53        let mut operation = self.client.operation(&routes::ADVANCED_SEARCH, &[]);
54        operation.query_optional("q", params.q.as_ref());
55        operation.query_optional("page", params.page.as_ref());
56        operation.query_optional("refine[from]", params.refine_from.as_ref());
57        operation.query_optional("refine[to]", params.refine_to.as_ref());
58        operation.query_optional("refine[subject]", params.refine_subject.as_ref());
59        operation.query_optional("refine[exact_phrase]", params.refine_exact_phrase.as_ref());
60        operation.query_optional("refine[required]", params.refine_required.as_ref());
61        operation.query_optional("refine[any]", params.refine_any.as_ref());
62        operation.query_optional("refine[none]", params.refine_none.as_ref());
63        operation.query_optional("refine[date]", params.refine_date.as_ref());
64        operation.query_optional("refine[in]", params.refine_in.as_ref());
65        operation.query_optional("refine[label]", params.refine_label.as_ref());
66        operation.query_optional("refine[attachment]", params.refine_attachment.as_ref());
67        self.client.send_page(operation).await
68    }
69
70    /// The advanced search refine form's options: boxes, date ranges, labels and attachment kinds.
71    pub async fn get_advanced_filters(
72        &self,
73    ) -> Result<GetAdvancedSearchFiltersResponseContent, Error> {
74        let operation = self
75            .client
76            .operation(&routes::GET_ADVANCED_SEARCH_FILTERS, &[]);
77        self.client.send(operation).await
78    }
79}