mod args;
mod ops;
mod ops_clauses;
mod query;
mod query_claused;
mod wire;
pub(crate) use args::{
ComposeQuery, FilterArg, FilterShape, HybridArgs, KnnArgs, MatchArgs, Query, parse_groups_args,
parse_match_score,
};
pub(crate) use wire::{decode_value, decode_view_cursor, encode_value, hex, peek_hydration};
use kevy_store::Store;
use crate::state::Ctx;
pub(crate) type Hydrated = Vec<Option<Vec<u8>>>;
pub(crate) type FieldSpans = (Vec<u8>, Vec<(u32, u32)>);
pub(crate) type HitSpans = Vec<FieldSpans>;
pub(crate) const ST_OK: u8 = 0;
pub(crate) const ST_BUILDING: u8 = 1;
pub(crate) const ST_NOINDEX: u8 = 2;
pub(crate) const ST_BADARGS: u8 = 3;
pub(crate) const ST_OVERBUDGET: u8 = 4;
pub(crate) const ST_NOTYET: u8 = 5;
pub(crate) const ST_CLAUSE: u8 = 6;
pub(crate) const ST_NOFIELD: u8 = 7;
pub(crate) fn probe_window(
ctx: &Ctx<'_>,
name: &[u8],
win: Option<&kevy_window::WindowRt>,
lower: &kevy_index::IndexValue,
) {
let Some(w) = win else { return };
if w.boundary() == i64::MIN {
return;
}
if let Some(cell) = ctx.state.catalogs.usage_cell(name)
&& let Some(v) = kevy_index::window_value_of(lower, w.shape)
{
cell.probe(v.saturating_sub(w.boundary()));
}
}
pub(crate) fn extension_op(ctx: &Ctx<'_>, store: &mut Store, argv: &[Vec<u8>]) -> Vec<u8> {
let verb = argv.first().map(Vec::as_slice).unwrap_or(b"");
if verb.eq_ignore_ascii_case(b"IDX.LIST") {
return query::op_list(ctx, store);
}
if argv.get(1).is_some_and(|a| a.eq_ignore_ascii_case(b"HYBRID")) {
return ops::op_hybrid(ctx, store, argv);
}
if argv.get(1).is_some_and(|a| a.eq_ignore_ascii_case(b"COMPOSE")) {
return ops::op_compose(ctx, store, argv);
}
if verb.eq_ignore_ascii_case(b"IDX.EXPLAIN") {
return query::op_explain(ctx, store, argv);
}
if verb.eq_ignore_ascii_case(b"MATCH.SCORE") {
return ops::op_match_score(ctx, store, argv);
}
if argv.get(2).is_some_and(|a| a.eq_ignore_ascii_case(b"MATCH")) {
return ops::op_match(ctx, store, argv);
}
if argv.get(2).is_some_and(|a| a.eq_ignore_ascii_case(b"KNN")) {
return ops::op_knn(ctx, store, argv);
}
if argv
.get(2)
.is_some_and(|a| a.eq_ignore_ascii_case(b"GROUP") || a.eq_ignore_ascii_case(b"GROUPS"))
{
return ops::op_agg(ctx, store, argv);
}
if argv.first().is_some_and(|v| v.eq_ignore_ascii_case(b"AGG.FETCH")) {
return ops::op_agg_fetch(ctx, store, argv);
}
if argv.first().is_some_and(|v| v.eq_ignore_ascii_case(b"IDX.REBUILD")) {
return ops::op_rebuild(ctx, store, argv);
}
query::op_query(ctx, store, argv, verb)
}