pub struct SearchQuery { /* private fields */ }Expand description
A builder for HAL search queries.
It maps directly onto the Solr query parameters used by the HAL API and covers every search mode listed in the HAL documentation:
- basic search —
SearchQuery::basic; - search within a field —
SearchQuery::field/SearchQuery::in_field; - several terms within a field —
SearchQuery::field_terms(OR) /SearchQuery::field_all_terms(AND); - proximity search —
SearchQuery::proximity; - field selection (
fl) —SearchQuery::fields; - pagination —
SearchQuery::rows/SearchQuery::start/SearchQuery::page; - facets —
SearchQuery::facet.
The builder methods consume and return self, so they can be chained.
Implementations§
Source§impl SearchQuery
impl SearchQuery
Sourcepub fn basic(query: impl Into<String>) -> Self
pub fn basic(query: impl Into<String>) -> Self
A basic search over all fields (the q parameter is used as-is).
This is the exact behaviour of the original chapter-16 library.
Sourcepub fn field(field: &str, value: &str) -> Self
pub fn field(field: &str, value: &str) -> Self
Search for a value within a specific field, e.g. field("title_t", "europe")
produces q=title_t:europe.
Sourcepub fn in_field(field: Field, value: &str) -> Self
pub fn in_field(field: Field, value: &str) -> Self
Fine-grained search scoped to a typed Field.
A multi-word value is grouped so that every word is searched within the
field, e.g. in_field(Field::Title, "open science") produces
q=title_t:(open science). An empty value falls back to a basic search.
Sourcepub fn field_terms<I, S>(field: &str, terms: I) -> Self
pub fn field_terms<I, S>(field: &str, terms: I) -> Self
Search for several terms within a single field, matching any of them
(Solr OR), e.g. field_terms("title_t", ["economic", "policy"])
produces q=title_t:(economic policy).
Sourcepub fn field_all_terms<I, S>(field: &str, terms: I) -> Self
pub fn field_all_terms<I, S>(field: &str, terms: I) -> Self
Search for several terms within a single field, matching all of them
(Solr AND), e.g. field_all_terms("title_t", ["economic", "policy"])
produces q=title_t:(economic AND policy).
Sourcepub fn proximity(field: &str, phrase: &str, distance: u32) -> Self
pub fn proximity(field: &str, phrase: &str, distance: u32) -> Self
Proximity search: find phrase within distance words inside field,
e.g. proximity("title_t", "economic policy", 3) produces
q=title_t:"economic policy"~3.
Sourcepub fn fields<I, S>(self, fields: I) -> Self
pub fn fields<I, S>(self, fields: I) -> Self
Restrict the returned fields (the Solr fl parameter).
Sourcepub fn page(self, page: u32, per_page: u32) -> Self
pub fn page(self, page: u32, per_page: u32) -> Self
Convenience pagination: page page (0-based) with per_page results each.
Sourcepub fn sort(self, sort: impl Into<String>) -> Self
pub fn sort(self, sort: impl Into<String>) -> Self
Set the sort clause (the Solr sort parameter), e.g. "producedDate_s desc".
Trait Implementations§
Source§impl Clone for SearchQuery
impl Clone for SearchQuery
Source§fn clone(&self) -> SearchQuery
fn clone(&self) -> SearchQuery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more