2023-05-29 11:46:41 +00:00
|
|
|
pub(crate) mod ft;
|
2023-06-19 18:41:13 +00:00
|
|
|
pub(crate) mod planner;
|
2023-08-01 09:57:05 +00:00
|
|
|
pub mod trees;
|
2023-05-29 11:46:41 +00:00
|
|
|
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::err::Error;
|
|
|
|
use crate::idx::ft::docids::DocId;
|
|
|
|
use crate::idx::ft::terms::TermId;
|
2023-08-01 09:57:05 +00:00
|
|
|
use crate::idx::trees::store::NodeId;
|
2023-07-18 18:32:38 +00:00
|
|
|
use crate::key::index::bc::Bc;
|
|
|
|
use crate::key::index::bd::Bd;
|
|
|
|
use crate::key::index::bf::Bf;
|
|
|
|
use crate::key::index::bi::Bi;
|
|
|
|
use crate::key::index::bk::Bk;
|
|
|
|
use crate::key::index::bl::Bl;
|
|
|
|
use crate::key::index::bo::Bo;
|
|
|
|
use crate::key::index::bp::Bp;
|
|
|
|
use crate::key::index::bs::Bs;
|
|
|
|
use crate::key::index::bt::Bt;
|
|
|
|
use crate::key::index::bu::Bu;
|
2023-05-29 11:46:41 +00:00
|
|
|
use crate::kvs::{Key, Val};
|
|
|
|
use crate::sql::statements::DefineIndexStatement;
|
2023-08-29 19:21:55 +00:00
|
|
|
use revision::Revisioned;
|
2023-05-29 11:46:41 +00:00
|
|
|
use serde::de::DeserializeOwned;
|
2023-06-19 18:41:13 +00:00
|
|
|
use serde::Serialize;
|
|
|
|
use std::sync::Arc;
|
2023-05-29 11:46:41 +00:00
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2023-07-11 18:22:31 +00:00
|
|
|
pub struct IndexKeyBase {
|
2023-06-19 18:41:13 +00:00
|
|
|
inner: Arc<Inner>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct Inner {
|
2023-05-29 11:46:41 +00:00
|
|
|
ns: String,
|
|
|
|
db: String,
|
|
|
|
tb: String,
|
|
|
|
ix: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IndexKeyBase {
|
|
|
|
pub(crate) fn new(opt: &Options, ix: &DefineIndexStatement) -> Self {
|
|
|
|
Self {
|
2023-06-19 18:41:13 +00:00
|
|
|
inner: Arc::new(Inner {
|
|
|
|
ns: opt.ns().to_string(),
|
|
|
|
db: opt.db().to_string(),
|
|
|
|
tb: ix.what.to_string(),
|
|
|
|
ix: ix.name.to_string(),
|
|
|
|
}),
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
fn new_bc_key(&self, term_id: TermId) -> Key {
|
|
|
|
Bc::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
term_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-05-29 11:46:41 +00:00
|
|
|
fn new_bd_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bd::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bi_key(&self, doc_id: DocId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bi::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bk_key(&self, doc_id: DocId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bk::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bl_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bl::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 18:31:15 +00:00
|
|
|
fn new_bo_key(&self, doc_id: DocId, term_id: TermId) -> Key {
|
|
|
|
Bo::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
term_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-05-29 11:46:41 +00:00
|
|
|
fn new_bp_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bp::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bf_key(&self, term_id: TermId, doc_id: DocId) -> Key {
|
|
|
|
Bf::new(
|
2023-06-19 18:41:13 +00:00
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
2023-05-29 11:46:41 +00:00
|
|
|
term_id,
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
fn new_bt_key(&self, node_id: Option<NodeId>) -> Key {
|
|
|
|
Bt::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
2023-05-29 11:46:41 +00:00
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bs_key(&self) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bs::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bu_key(&self, term_id: TermId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bu::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
term_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-29 19:21:55 +00:00
|
|
|
/// This trait provides `Revision` based default implementations for serialization/deserialization
|
|
|
|
trait VersionedSerdeState
|
2023-05-29 11:46:41 +00:00
|
|
|
where
|
2023-08-29 19:21:55 +00:00
|
|
|
Self: Sized + Serialize + DeserializeOwned + Revisioned,
|
2023-05-29 11:46:41 +00:00
|
|
|
{
|
|
|
|
fn try_to_val(&self) -> Result<Val, Error> {
|
2023-08-29 19:21:55 +00:00
|
|
|
let mut val = Vec::new();
|
|
|
|
self.serialize_revisioned(&mut val)?;
|
|
|
|
Ok(val)
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn try_from_val(val: Val) -> Result<Self, Error> {
|
2023-08-29 19:21:55 +00:00
|
|
|
Ok(Self::deserialize_revisioned(&mut val.as_slice())?)
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|