Skip to main content

Query

Struct Query 

Source
pub struct Query {
    pub search: Option<Search>,
    pub id_list: Vec<ArticleId>,
    pub start: Option<usize>,
    pub max_results: Option<usize>,
    pub sort_by: Option<SortBy>,
    pub sort_order: Option<SortOrder>,
}
Expand description

One request to arXiv’s /api/query route.

let query = Query::new(Search::category("cs.LG").and(Search::title("transformer")))
    .max_results(50)
    .sort_by(SortBy::SubmittedDate);

A Search, a &str (read as a search of every field) and an ArticleId all convert into a Query, so the common cases need no builder at all.

Fields§

§search: Option<Search>

the expression to match, sent as search_query

§id_list: Vec<ArticleId>

the articles to fetch, sent as id_list

With a search beside it these are narrowed to the ones that also match; on their own they are returned as they are.

§start: Option<usize>

the offset into the result set to start at, sent as start

§max_results: Option<usize>

how many results to return, sent as max_results

§sort_by: Option<SortBy>

what to order the results by, sent as sortBy

§sort_order: Option<SortOrder>

which end of that ordering comes first, sent as sortOrder

Implementations§

Source§

impl Query

Source

pub const MAX_RESULTS: usize = 2_000

The most results arXiv’s user manual says it serves in one request.

Query::route refuses more, and Arxiv::paginate is how to reach the rest. The api does not police the number itself – asked for 2100 it currently answers with 2100 – but that is undocumented behaviour of a request arXiv already describes as slow, and it gives out entirely, with a 500, not far above.

Source

pub const MAX_REACHABLE: usize = 30_000

The deepest arXiv lets a query page.

A start at or near this is answered with a 500, whatever totalResults said, so a search that has to reach further has to be split into narrower ones – by date range, or by category. Arxiv::paginate stops here rather than walking into it.

Source

pub fn new(search: Search) -> Self

A query for everything matching search.

Source

pub fn ids<I>(ids: I) -> Result<Self>
where I: IntoIterator, I::Item: AsRef<str>,

A query for the articles with these identifiers.

let query = Query::ids(["2101.00001", "hep-ex/0307015"])?;
Source

pub fn search(self, search: impl Into<Option<Search>>) -> Self

Narrow this query to articles matching search as well.

Source

pub fn id(self, id: ArticleId) -> Self

Add an article to the ones this query asks for.

Source

pub fn start(self, start: impl Into<Option<usize>>) -> Self

Start at the startth result rather than the first.

Source

pub fn max_results(self, max_results: impl Into<Option<usize>>) -> Self

Return at most max_results results, at most Query::MAX_RESULTS of them. Defaults to the 10 arXiv returns when not asked.

Source

pub fn sort_by(self, sort_by: impl Into<Option<SortBy>>) -> Self

Order the results by sort_by. Defaults to arXiv’s own relevance order.

Source

pub fn sort_order(self, sort_order: impl Into<Option<SortOrder>>) -> Self

Return the results ascending or descending.

Source

pub fn route(&self) -> Result<String>

The route this query renders to, /api/query?….

§Errors

Refuses a query arXiv would answer with an error feed rather than results: one that names neither a search nor an identifier, one whose max_results is over Query::MAX_RESULTS, and one carrying a term that cannot survive the query syntax – see Error::UnsendableTerm.

Source

pub fn to_url(&self, base_url: &str) -> Result<String>

The full url this query is sent to, base_url with the route appended.

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Query

Source§

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

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

impl Default for Query

Source§

fn default() -> Self

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

impl Eq for Query

Source§

impl From<&str> for Query

Reads free form text as a search of every field, so client.search("electron") means what it looks like.

Source§

fn from(terms: &str) -> Self

Converts to this type from the input type.
Source§

impl From<ArticleId> for Query

Source§

fn from(id: ArticleId) -> Self

Converts to this type from the input type.
Source§

impl From<Search> for Query

Source§

fn from(search: Search) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Query

Source§

fn from(terms: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Query

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Query

Auto Trait Implementations§

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

§

impl UnwindSafe for Query

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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