[−][src]Struct mycelium_index::Index
Index
Will hold multiple types of indexes back into Db
Fields
db: Db
Methods
impl Index
[src]
pub fn init(config: Option<Config>) -> Result<Index>
[src]
Init
Initialize containers. If first run a system folder will be created otherwise nothing else is done.
-
Parameters
- config: Config for Db defaults to Config::default()
-
Return
- Result: Index
use crate::mycelium_index::prelude::*; match Index::init(None) { Ok(_) => assert!(true), Err(_) => assert!(false, "Error creating db") }
pub fn add(&self, tag: &str, item: &[u8]) -> Result<DbId>
[src]
Add
Add item to database
-
Parameters
- tag: container id to add item to
- item: byte array of item
- type_name: optional type id
-
Return
- Result: [u8;16] id of item added to db/index
use crate::mycelium_index::prelude::*; // new db let idb = Index::init(None).expect("Failed to create idb"); // add item let id = idb.add("dog", b"shepard").expect("Failed to add item"); assert!(id != [0;16])
pub fn add_indexed(
&self,
tag: &str,
item: &[u8],
hit_box: &[&str]
) -> Result<DbId>
[src]
&self,
tag: &str,
item: &[u8],
hit_box: &[&str]
) -> Result<DbId>
Add Indexed
Add an item to the database and any implemented indexes with given association.
-
Parameters
- tag: container id to put item in
- item: byte array of item
- hit_box: index terms this item should be associated with ["fish", "dog"]
-
Return
- Result: [u8; 16] unique db id of item added
use crate::mycelium_index::prelude::*; // new db let idb = Index::init(None).expect("Failed to create idb"); // add item with index associates let id = idb.add_indexed("dog", b"good boy", &["shepherd", "working dog", "pet"]) .expect("Failed to add item"); assert!(id != [0 as u8;16])
pub fn get(&self, tag: &str, ids: &[DbId]) -> Option<Vec<Node>>
[src]
Get
Get an item/items from container
-
Parameters
- tag: container id
- ids: array of ids to retrieve [[u8;16],[u8;16]
-
Return
- Option: Vector of matches
use crate::mycelium_index::prelude::*; // new db let idb = Index::init(None).expect("Failed to create idb"); // add item let id = idb.add("tag", b"some stuff").expect("Failed to add to idb"); let id2 = idb.add("tag", b"some stuff 2").expect("Failed to add to idb"); let id3 = idb.add("tag", b"some stuff 3").expect("Failed to add to idb"); // get item let f_item = idb.get("tag", &[id, id3]).expect("Failed to get item from idb"); assert!(f_item.len() == 2); let ids: Vec<[u8;16]> = f_item.iter().map(|node| node.get_id()).collect(); assert!(ids.contains(&id) && ids.contains(&id3) && !ids.contains(&id2));
pub fn get_system_id(&self) -> DbId
[src]
pub fn list_tags(&self) -> Vec<String>
[src]
pub fn load_tag(&mut self, tag: &str) -> Result<()>
[src]
Load Tag
Load a tag before performing operations over it. Destructive if called over loaded tag drop current and load from disk.
pub fn search(&self, tag: &str, hit_list: &[&str]) -> Option<Vec<Node>>
[src]
Search
Search for items in container
-
Parameters:
- tag: container id
- hit_list: search items
-
Result:
- Option: List of nodes that are associated with hit_list items. TODO: Order by match count
use crate::mycelium_index::prelude::*; // new db let idb = Index::init(None).expect("Failed to create db"); // add some nodes let id_mut = idb.add_indexed("tag", b"Zippy", &["Shepherd", "Husky", "Akita", "Lab"]) .expect("Failed to add item to idb"); let id_boxer = idb.add_indexed("tag", b"Trip", &["Boxer"]) .expect("Failed to add item to idb"); let id_mut2 = idb.add_indexed("tag", b"Buddy", &["Boxer", "Lab"]) .expect("Failed to add item to idb"); let id_pointer = idb.add_indexed("tag", b"Sam", &["Pointer"]) .expect("Failed to add item to idb"); let dogs = idb.search("tag", &["Boxer", "Lab"]).unwrap(); assert!(dogs.len() == 3); // not case sensitive let dog = idb.search("tag", &["pointer"]).unwrap(); assert!(dog.len() == 1);
pub fn save_all(&self) -> Result<()>
[src]
Auto Trait Implementations
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl !UnwindSafe for Index
impl !RefUnwindSafe for Index
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,