switch to single search function

This commit is contained in:
askiiart 2024-11-30 21:08:40 -06:00
parent 286262372a
commit 492579035d
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30
3 changed files with 48 additions and 16 deletions

View file

@ -33,7 +33,7 @@ struct SearchForm {
impl SearchForm { impl SearchForm {
/// Converts it to a SearchParameters object /// Converts it to a SearchParameters object
fn to_parameters(&self, conf: Config) -> SearchParameters { fn to_parameters(&self, conf: Config) -> InternalSearchParameters {
// TODO: Clean up this code - split it into a separate function? // TODO: Clean up this code - split it into a separate function?
let mut categories: Option<Vec<u32>> = None; let mut categories: Option<Vec<u32>> = None;
if !self.cat.is_none() { if !self.cat.is_none() {
@ -72,7 +72,7 @@ impl SearchForm {
limit = conf.caps.limits.max; limit = conf.caps.limits.max;
} }
return SearchParameters { return InternalSearchParameters {
q: self.q.clone(), q: self.q.clone(),
apikey: self.apikey.clone(), apikey: self.apikey.clone(),
categories: categories, categories: categories,

View file

@ -112,24 +112,60 @@ pub struct Caps {
/// The search function (`/api?t=search`) and capabilities (`/api?t=caps` - struct [`Caps`]) are required /// The search function (`/api?t=search`) and capabilities (`/api?t=caps` - struct [`Caps`]) are required
/// Everything else is optional /// Everything else is optional
pub struct Config { pub struct Config {
/// The function to use for a free text search /// The function to use for all search types
///
/// What search types are available is dependent on what's marked as available in the `searching` field of `caps` ([`Caps`])
///
/// Search types: `search`, `tv-search`, `movie-search`, `audio-search`, `book-search`
pub search: SearchFunc, pub search: SearchFunc,
/// The auth function - if not specified, then no authorization is needed. /// The auth function - if not specified, then no authorization is needed.
pub auth: Option<AuthFunc>, pub auth: Option<AuthFunc>,
/// The capabilities of the indexer - see [`Caps`] /// The capabilities of the indexer - see [`Caps`]
pub caps: Caps, pub caps: Caps,
/// The function to use for a tv search
pub tvsearch: Option<SearchFunc>,
/// The function to use for a movie search
pub movie: Option<SearchFunc>,
/// The function to use for a music search
pub music: Option<SearchFunc>,
/// The function to use for a book search
pub book: Option<SearchFunc>,
} }
/// An internal struct to hold the parameters for a search
///
/// Before being sent to the "client" program, it's turned into a SearchParameters object by `to_search_param()`, adding the search type
#[derive(Debug, Clone, PartialEq, Eq, FromForm)] #[derive(Debug, Clone, PartialEq, Eq, FromForm)]
pub(crate) struct SearchParameters { pub(crate) struct InternalSearchParameters {
/// The text query for the search
pub(crate) q: Option<String>,
/// The apikey, for authentication
pub(crate) apikey: Option<String>,
/// A [`Vec`] containing the numeric category IDs to be included in the search results
pub(crate) categories: Option<Vec<u32>>,
/// A [`Vec`] containing the extended attribute names to be included in the search results
pub(crate) attributes: Option<Vec<String>>,
/// Whether *all* extended attributes should be included in the search results; overrules `attributes`
pub(crate) extended_attrs: Option<bool>,
/// How many items to skip/offset by in the results.
pub(crate) offset: Option<u32>,
/// The maximum number of items to return - also limited to whatever `limits` is in [`Caps`]
pub(crate) limit: u32,
}
impl InternalSearchParameters {
pub(crate) fn to_search_param(&self, search_type: String) -> SearchParameters {
return SearchParameters {
search_type: search_type,
q: self.q.clone(),
apikey: self.apikey.clone(),
categories: self.categories.clone(),
attributes: self.attributes.clone(),
extended_attrs: self.extended_attrs,
offset: self.offset,
limit: self.limit,
};
}
}
/// Holds the parameters for a search query
pub struct SearchParameters {
/// What type of search this is
///
/// Search types: `search`, `tv-search`, `movie-search`, `audio-search`, `book-search`
pub(crate) search_type: String,
/// The text query for the search /// The text query for the search
pub(crate) q: Option<String>, pub(crate) q: Option<String>,
/// The apikey, for authentication /// The apikey, for authentication

View file

@ -76,10 +76,6 @@ pub(crate) fn create_empty_config() -> Config {
genres: Some(genres), genres: Some(genres),
tags: Some(tags), tags: Some(tags),
}, },
book: None,
movie: None,
music: None,
tvsearch: None,
}; };
} }