Skip to main content

IndexKind

Enum IndexKind 

Source
#[non_exhaustive]
pub enum IndexKind { Range, Unique, Text, Ann, Agg, }
Expand description

Index kind (KIND range|unique).

use kevy_index::IndexKind;
assert_eq!(IndexKind::parse(b"UNIQUE"), Some(IndexKind::Unique));
assert_eq!(IndexKind::parse(IndexKind::Agg.tag().as_bytes()), Some(IndexKind::Agg));
assert_eq!(IndexKind::parse(b"hash"), None);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Range

Ordered scan over (value, key) pairs.

use kevy_index::{IndexValue, Segment};
let mut seg = Segment::new();
seg.apply(b"u:1", None, Some(IndexValue::I64(30)));
seg.apply(b"u:2", None, Some(IndexValue::I64(20)));
let (hits, _) = seg.range(&IndexValue::I64(0), &IndexValue::I64(99), None, 10);
assert_eq!(hits[0].0, b"u:2", "value order, not key order");
§

Unique

Point lookup by value; duplicates recorded (declarative fence: uniqueness is verified, not write-enforced).

use kevy_index::{IndexValue, Segment};
let mut seg = Segment::new();
seg.apply(b"u:1", None, Some(IndexValue::Str(b"a@x".to_vec())));
seg.apply(b"u:2", None, Some(IndexValue::Str(b"a@x".to_vec())));
// the second write is not refused; the lookup shows the duplicate
assert_eq!(seg.eq(&IndexValue::Str(b"a@x".to_vec()), 10).len(), 2);
§

Text

Full-text: the field tokenizes into an inverted segment (kevy-text); queried with MATCH, BM25-ranked.

use kevy_index::{FieldSpec, IndexKind, IndexSpec, ValType};
let fields = vec![FieldSpec::new("title").with_weight(2.0), FieldSpec::new("body")];
let text = IndexSpec::builder("posts", "post:", IndexKind::Text, ValType::Str)
    .with_fields(fields)
    .build()?;
assert_eq!(text.fields().len(), 2, "only text serves several fields");
§

Ann

ANN: the field holds an f32 LE vector indexed in an HNSW graph (kevy-vector); queried with KNN, distance-ranked.

use kevy_index::{AnnSpec, IndexKind, IndexSpec, ValType};
let b = IndexSpec::builder("emb", "doc:", IndexKind::Ann, ValType::Vector).with_field("v");
assert!(b.clone().build().is_err(), "an ANN index needs its parameters");
assert_eq!(b.with_ann(AnnSpec::new(128)).build()?.ann(), Some(AnnSpec::new(128)));
§

Agg

Aggregate: per-group count/sum/min/max of the field, grouped by IndexSpec::group_by; queried with GROUP/GROUPS.

use kevy_index::{IndexKind, IndexSpec, ValType};
let spend = IndexSpec::builder("spend", "o:", IndexKind::Agg, ValType::F64)
    .with_field("total")
    .with_group_by("region")
    .build()?;
assert_eq!(spend.group_by(), Some(&b"region"[..]));

Implementations§

Source§

impl IndexKind

Source

pub fn tag(self) -> &'static str

Wire tag.

Source

pub fn parse(raw: &[u8]) -> Option<IndexKind>

Parse a wire tag.

Trait Implementations§

Source§

impl Clone for IndexKind

Source§

fn clone(&self) -> IndexKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for IndexKind

Source§

impl Debug for IndexKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for IndexKind

Source§

impl Hash for IndexKind

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for IndexKind

Source§

fn eq(&self, other: &IndexKind) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for IndexKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.