Struct core_api_client::SearchQuery

source ·
pub struct SearchQuery<T1 = String, T2 = String>
where T1: ToString, T2: ToString,
{ /* 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 of Filter 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 the SearchQuery object into a string to be used in the API request.

Implementations§

source§

impl<T1, T2> SearchQuery<T1, T2>
where T1: ToString, T2: ToString,

source

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));
source

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));
source

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>
where T1: ToString + Clone, T2: ToString + Clone,

source§

fn clone(&self) -> SearchQuery<T1, T2>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T1, T2> Debug for SearchQuery<T1, T2>
where T1: ToString + Debug, T2: ToString + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T1, T2> Default for SearchQuery<T1, T2>
where T1: ToString + Default, T2: ToString + Default,

source§

fn default() -> SearchQuery<T1, T2>

Returns the “default value” for a type. Read more
source§

impl<'de, T1, T2> Deserialize<'de> for SearchQuery<T1, T2>
where T1: ToString + Deserialize<'de>, T2: ToString + Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T1, T2> Display for SearchQuery<T1, T2>
where T1: ToString, T2: ToString,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T1, T2> Hash for SearchQuery<T1, T2>
where T1: ToString + Hash, T2: ToString + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T1, T2> PartialEq for SearchQuery<T1, T2>
where T1: ToString + PartialEq, T2: ToString + PartialEq,

source§

fn eq(&self, other: &SearchQuery<T1, T2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T1, T2> PartialOrd for SearchQuery<T1, T2>

source§

fn partial_cmp(&self, other: &SearchQuery<T1, T2>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T1, T2> Serialize for SearchQuery<T1, T2>
where T1: ToString + Serialize, T2: ToString + Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T1, T2> StructuralPartialEq for SearchQuery<T1, T2>
where T1: ToString, T2: ToString,

Auto Trait Implementations§

§

impl<T1, T2> Freeze for SearchQuery<T1, T2>

§

impl<T1, T2> RefUnwindSafe for SearchQuery<T1, T2>

§

impl<T1, T2> Send for SearchQuery<T1, T2>
where T1: Send, T2: Send,

§

impl<T1, T2> Sync for SearchQuery<T1, T2>
where T1: Sync, T2: Sync,

§

impl<T1, T2> Unpin for SearchQuery<T1, T2>
where T1: Unpin, T2: Unpin,

§

impl<T1, T2> UnwindSafe for SearchQuery<T1, T2>
where T1: UnwindSafe, T2: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,