Struct core_api_client::SearchQuery
source · pub struct SearchQuery<T1 = String, T2 = String>{ /* private fields */ }
Expand description
SearchQuery
is a structure that represents a search query to the API. It allows the user to define the criteria
to filter data from the API.
SearchQuery
contains various search parameters such as limit
, offset
, scroll
and stats
that can be
optionally set for advanced search operations.
A search operation can be composed of multiple Filter
conditions that can be linked using logical AND/OR
operators. Each Filter
condition consists of a FilterOperator
that defines the type of comparison to be made.
§Example
use core_api_client::FilterOperator;
use core_api_client::Api;
let api = Api::from("API_KEY");
let query = api.paged_search(10, 0)
.and(FilterOperator::Exists("doi"))
.and(FilterOperator::Bigger("citationCount", 20));
let resp = api.search_works(query);
§Fields
filters
: A vector ofFilter
structs that represent the conditions of the search query.limit
: The maximum number of results to return. Defaults to None.offset
: The number of results to skip before starting to fetch. Defaults to None.scroll
: Enable/disable the scrolling functionality. Defaults to None.stats
: Enable/disable the statistics functionality. Defaults to None.
§Methods
and
: Adds a new filter condition with a logical AND operator.or
: Adds a new filter condition with a logical OR operator.parse
: Parses theSearchQuery
object into a string to be used in the API request.
Implementations§
source§impl<T1, T2> SearchQuery<T1, T2>
impl<T1, T2> SearchQuery<T1, T2>
sourcepub fn and(self, operator: FilterOperator<T1, T2>) -> Self
pub fn and(self, operator: FilterOperator<T1, T2>) -> Self
Adds a filter to the SearchQuery
with an AND logical operator.
§Arguments
operator: FilterOperator<T1, T2>
- The filter operator and its associated values to be added to the search query.
§Example
use core_api_client::{Api, SearchQuery, FilterOperator};
let api = Api::from("API_KEY");
let query = api.paged_search(10, 0)
.and(FilterOperator::Exists("doi"))
.and(FilterOperator::Bigger("citationCount", 20));
sourcepub fn or(self, operator: FilterOperator<T1, T2>) -> Self
pub fn or(self, operator: FilterOperator<T1, T2>) -> Self
Adds a filter to the SearchQuery
with an OR logical operator.
§Arguments
operator: FilterOperator<T1, T2>
- The filter operator and its associated values to be added to the search query.
§Example
use core_api_client::{Api, SearchQuery, FilterOperator};
let api = Api::from("API_KEY");
let query = api.paged_search(10, 0)
.or(FilterOperator::Exists("doi"))
.or(FilterOperator::Bigger("citationCount", 20));
sourcepub fn parse(self) -> String
pub fn parse(self) -> String
Converts the SearchQuery
instance into a string that represents a valid URL query string.
This method concatenates all added filters with their corresponding logical operators, and includes
additional parameters like limit
, offset
, scroll
and stats
, if they are present.
§Returns
String
- The resulting URL query string.
§Example
use core_api_client::{Api, SearchQuery, FilterOperator};
let api = Api::from("API_KEY");
let query = api.paged_search(10, 0)
.and(FilterOperator::Eq("publisher", "OJS"));
assert_eq!("?limit=10&offset=0&q=%20AND%20publisher=OJS".to_string(), query.parse());
Trait Implementations§
source§impl<T1, T2> Clone for SearchQuery<T1, T2>
impl<T1, T2> Clone for SearchQuery<T1, T2>
source§fn clone(&self) -> SearchQuery<T1, T2>
fn clone(&self) -> SearchQuery<T1, T2>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T1, T2> Debug for SearchQuery<T1, T2>
impl<T1, T2> Debug for SearchQuery<T1, T2>
source§impl<T1, T2> Default for SearchQuery<T1, T2>
impl<T1, T2> Default for SearchQuery<T1, T2>
source§fn default() -> SearchQuery<T1, T2>
fn default() -> SearchQuery<T1, T2>
source§impl<'de, T1, T2> Deserialize<'de> for SearchQuery<T1, T2>
impl<'de, T1, T2> Deserialize<'de> for SearchQuery<T1, T2>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T1, T2> Display for SearchQuery<T1, T2>
impl<T1, T2> Display for SearchQuery<T1, T2>
source§impl<T1, T2> Hash for SearchQuery<T1, T2>
impl<T1, T2> Hash for SearchQuery<T1, T2>
source§impl<T1, T2> PartialEq for SearchQuery<T1, T2>
impl<T1, T2> PartialEq for SearchQuery<T1, T2>
source§fn eq(&self, other: &SearchQuery<T1, T2>) -> bool
fn eq(&self, other: &SearchQuery<T1, T2>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<T1, T2> PartialOrd for SearchQuery<T1, T2>
impl<T1, T2> PartialOrd for SearchQuery<T1, T2>
source§fn partial_cmp(&self, other: &SearchQuery<T1, T2>) -> Option<Ordering>
fn partial_cmp(&self, other: &SearchQuery<T1, T2>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more