pub struct GroupingComponent { /* private fields */ }
Expand description
Group documents by a field or query.
§Examples
use solrstice::{GroupingComponent, SelectQuery, SolrBasicAuth, SolrSingleServerHost};
let response = SelectQuery::new()
.fq(["age:[* TO *]"])
.grouping(&GroupingComponent::new().fields(["age"]).limit(10))
.execute(&context, "collection_name")
.await?;
let groups = response.get_groups().ok_or("No groups")?;
let age_group = groups.get("age").ok_or("No age group")?;
for group in age_group.get_field_result().ok_or("No field result")? {
println!("Group key: {}", group.get_group_value::<usize>()?);
let docs = group.get_doc_list().get_docs::<serde_json::Value>()?;
}
Implementations§
Source§impl GroupingComponent
impl GroupingComponent
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GroupingComponentBuilder.
§Examples
use solrstice::{GroupingComponent, SelectQuery, SolrBasicAuth, SolrSingleServerHost};
let response = SelectQuery::new()
.fq(["age:[* TO *]"])
.grouping(&GroupingComponent::new().fields(["age"]).limit(10))
.execute(&context, "collection_name")
.await?;
let groups = response.get_groups().ok_or("No groups")?;
let age_group = groups.get("age").ok_or("No age group")?;
for group in age_group.get_field_result().ok_or("No field result")? {
println!("Group key: {}", group.get_group_value::<usize>()?);
let docs = group.get_doc_list().get_docs::<serde_json::Value>()?;
}
Sourcepub fn fields<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>(
self,
fields: O,
) -> Self
pub fn fields<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>( self, fields: O, ) -> Self
Fields to group by.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().fields(["age"]);
Sourcepub fn queries<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>(
self,
queries: O,
) -> Self
pub fn queries<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>( self, queries: O, ) -> Self
Queries to group by.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().queries(["age:[0 TO 59]", "age:[60 TO *]"]);
Sourcepub fn limit<O: Into<Option<usize>>>(self, limit: O) -> Self
pub fn limit<O: Into<Option<usize>>>(self, limit: O) -> Self
Maximum number of documents per group.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().limit(10);
Sourcepub fn offset<O: Into<Option<usize>>>(self, offset: O) -> Self
pub fn offset<O: Into<Option<usize>>>(self, offset: O) -> Self
Initial offset
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().limit(10).offset(10);
Sourcepub fn sort<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>(
self,
sort: O,
) -> Self
pub fn sort<S: Into<String>, I: IntoIterator<Item = S>, O: Into<Option<I>>>( self, sort: O, ) -> Self
How to sort the documents in the groups.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().sort(["age asc"]);
Sourcepub fn format<O: Into<Option<GroupFormatting>>>(self, format: O) -> Self
pub fn format<O: Into<Option<GroupFormatting>>>(self, format: O) -> Self
How to format the groups.
§Examples
use solrstice::{GroupingComponent, GroupFormatting};
GroupingComponent::new().format(GroupFormatting::Simple);
Sourcepub fn main<O: Into<Option<bool>>>(self, main: O) -> Self
pub fn main<O: Into<Option<bool>>>(self, main: O) -> Self
Put the results in the main result set.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().main(true);
Sourcepub fn n_groups<O: Into<Option<bool>>>(self, n_groups: O) -> Self
pub fn n_groups<O: Into<Option<bool>>>(self, n_groups: O) -> Self
Include the number of groups that have matched the query.
§Examples
use solrstice::GroupingComponent;
GroupingComponent::new().n_groups(true);
Trait Implementations§
Source§impl AsRef<GroupingComponent> for GroupingComponent
impl AsRef<GroupingComponent> for GroupingComponent
Source§impl Clone for GroupingComponent
impl Clone for GroupingComponent
Source§fn clone(&self) -> GroupingComponent
fn clone(&self) -> GroupingComponent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for GroupingComponent
impl Debug for GroupingComponent
Source§impl Default for GroupingComponent
impl Default for GroupingComponent
Source§fn default() -> GroupingComponent
fn default() -> GroupingComponent
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for GroupingComponent
impl<'de> Deserialize<'de> for GroupingComponent
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&GroupingComponent> for GroupingComponent
impl From<&GroupingComponent> for GroupingComponent
Source§fn from(component: &GroupingComponent) -> Self
fn from(component: &GroupingComponent) -> Self
Converts to this type from the input type.
Source§impl PartialEq for GroupingComponent
impl PartialEq for GroupingComponent
Source§impl Serialize for GroupingComponent
impl Serialize for GroupingComponent
impl StructuralPartialEq for GroupingComponent
Auto Trait Implementations§
impl Freeze for GroupingComponent
impl RefUnwindSafe for GroupingComponent
impl Send for GroupingComponent
impl Sync for GroupingComponent
impl Unpin for GroupingComponent
impl UnwindSafe for GroupingComponent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more