pub trait FlussoMultiDocument: Sized {
const TARGETS: &'static [(&'static str, &'static str)];
// Required method
fn decode(physical_index: &str, source: Value) -> Result<Self>;
// Provided method
fn query() -> MultiSearch<Self> { ... }
}Expand description
A union of FlussoDocument types searched
together — one query, one blended result list, each hit decoded into the
variant matching its index.
#[derive(FlussoMultiDocument)] (the derive feature) implements it for
an enum with one single-field variant per document type. Without the
derive, the impl is written by hand — exactly what the derive generates:
use flusso_query::{FlussoDocument, FlussoIndex, FlussoMultiDocument, Error, Result, Segment};
use serde_json::Value;
/// One item in the storefront's blended search — name it after the
/// surface it serves, like your document structs.
enum StoreItem {
User(User),
Order(Order),
}
impl FlussoMultiDocument for StoreItem {
const TARGETS: &'static [(&'static str, &'static str)] = &[
(User::INDEX, User::SCHEMA_HASH),
(Order::INDEX, Order::SCHEMA_HASH),
];
fn decode(physical_index: &str, source: Value) -> Result<Self> {
if physical_index == User::physical_index() {
return Ok(Self::User(serde_json::from_value(source)?));
}
if physical_index == Order::physical_index() {
return Ok(Self::Order(serde_json::from_value(source)?));
}
Err(Error::UnexpectedIndex { index: physical_index.to_owned() })
}
}Required Associated Constants§
Required Methods§
Provided Methods§
Sourcefn query() -> MultiSearch<Self>
fn query() -> MultiSearch<Self>
Start a typed query across all of this union’s indexes. Like
FlussoIndex::query, the returned
builder is a plain client-free value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".