Indexer

Struct Indexer 

Source
pub struct Indexer<T: Indexable> { /* private fields */ }

Implementations§

Source§

impl<T: Indexable> Indexer<T>

Source

pub fn new(path: &Path) -> Self

Examples found in repository?
examples/filter.rs (line 12)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    let filter = HashMap::from([
20        ("author", "Bogdan")
21    ]);
22    let regex_search_result = indexer.hybrid_search(filter, "name", "Rust", 10);
23    for book in regex_search_result {
24        println!("{:?}", book);
25    }
26}
More examples
Hide additional examples
examples/index_and_filter_delete.rs (line 12)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    indexer.delete_using_filters(HashMap::from([("author", "Steve Klabnik and Carol Nichols"), ("name", "The Rust Programming Language")]));
26    indexer.commit();
27
28    println!("After deleting");
29    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
30    for book in regex_search_result {
31        println!("{:?}", book);
32    }
33}
examples/index_and_term_delete.rs (line 12)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    let field = Book::get_struct_info()
26        .generate_schema()
27        .get_field("author")
28        .unwrap();
29
30    let term = Term::from_field_text(field, "Steve Klabnik and Carol Nichols");
31    indexer.delete_using_term(term);
32    indexer.commit();
33
34    println!("After deleting");
35    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
36    for book in regex_search_result {
37        println!("{:?}", book);
38    }
39}
Source

pub fn index(&mut self, data: T)

Examples found in repository?
examples/filter.rs (line 15)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    let filter = HashMap::from([
20        ("author", "Bogdan")
21    ]);
22    let regex_search_result = indexer.hybrid_search(filter, "name", "Rust", 10);
23    for book in regex_search_result {
24        println!("{:?}", book);
25    }
26}
More examples
Hide additional examples
examples/index_and_filter_delete.rs (line 15)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    indexer.delete_using_filters(HashMap::from([("author", "Steve Klabnik and Carol Nichols"), ("name", "The Rust Programming Language")]));
26    indexer.commit();
27
28    println!("After deleting");
29    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
30    for book in regex_search_result {
31        println!("{:?}", book);
32    }
33}
examples/index_and_term_delete.rs (line 15)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    let field = Book::get_struct_info()
26        .generate_schema()
27        .get_field("author")
28        .unwrap();
29
30    let term = Term::from_field_text(field, "Steve Klabnik and Carol Nichols");
31    indexer.delete_using_term(term);
32    indexer.commit();
33
34    println!("After deleting");
35    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
36    for book in regex_search_result {
37        println!("{:?}", book);
38    }
39}
Source

pub fn delete(&mut self, data: T)

Source

pub fn delete_using_term(&mut self, term: Term)

Examples found in repository?
examples/index_and_term_delete.rs (line 31)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    let field = Book::get_struct_info()
26        .generate_schema()
27        .get_field("author")
28        .unwrap();
29
30    let term = Term::from_field_text(field, "Steve Klabnik and Carol Nichols");
31    indexer.delete_using_term(term);
32    indexer.commit();
33
34    println!("After deleting");
35    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
36    for book in regex_search_result {
37        println!("{:?}", book);
38    }
39}
Source

pub fn delete_using_filters(&mut self, filters: HashMap<&str, &str>)

Examples found in repository?
examples/index_and_filter_delete.rs (line 25)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    indexer.delete_using_filters(HashMap::from([("author", "Steve Klabnik and Carol Nichols"), ("name", "The Rust Programming Language")]));
26    indexer.commit();
27
28    println!("After deleting");
29    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
30    for book in regex_search_result {
31        println!("{:?}", book);
32    }
33}
Source

pub fn update(&mut self, data: T)

Source

pub fn commit(&mut self)

Examples found in repository?
examples/filter.rs (line 17)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    let filter = HashMap::from([
20        ("author", "Bogdan")
21    ]);
22    let regex_search_result = indexer.hybrid_search(filter, "name", "Rust", 10);
23    for book in regex_search_result {
24        println!("{:?}", book);
25    }
26}
More examples
Hide additional examples
examples/index_and_filter_delete.rs (line 17)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    indexer.delete_using_filters(HashMap::from([("author", "Steve Klabnik and Carol Nichols"), ("name", "The Rust Programming Language")]));
26    indexer.commit();
27
28    println!("After deleting");
29    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
30    for book in regex_search_result {
31        println!("{:?}", book);
32    }
33}
examples/index_and_term_delete.rs (line 17)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    let field = Book::get_struct_info()
26        .generate_schema()
27        .get_field("author")
28        .unwrap();
29
30    let term = Term::from_field_text(field, "Steve Klabnik and Carol Nichols");
31    indexer.delete_using_term(term);
32    indexer.commit();
33
34    println!("After deleting");
35    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
36    for book in regex_search_result {
37        println!("{:?}", book);
38    }
39}
Source

pub fn search( &self, filter: HashMap<&str, &str>, field_name: &str, query: &str, result_count: usize, ) -> Vec<T>

Uses regex pattern matching query along with fuzzy search. Maybe slow.

Examples found in repository?
examples/filter.rs (line 22)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    let filter = HashMap::from([
20        ("author", "Bogdan")
21    ]);
22    let regex_search_result = indexer.hybrid_search(filter, "name", "Rust", 10);
23    for book in regex_search_result {
24        println!("{:?}", book);
25    }
26}
More examples
Hide additional examples
examples/index_and_filter_delete.rs (line 20)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    indexer.delete_using_filters(HashMap::from([("author", "Steve Klabnik and Carol Nichols"), ("name", "The Rust Programming Language")]));
26    indexer.commit();
27
28    println!("After deleting");
29    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
30    for book in regex_search_result {
31        println!("{:?}", book);
32    }
33}
examples/index_and_term_delete.rs (line 20)
8fn main() {
9    let path = "/home/salman/text-search-test";
10    let _ = fs::remove_dir_all(&path);
11    let _ = fs::create_dir(&path);
12    let mut indexer = Indexer::<Book>::new(Path::new(path));
13    let books = Book::get_sample_books();
14    for book in &books {
15        indexer.index(book.clone());
16    }
17    indexer.commit();
18
19    println!("Before deleting");
20    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
21    for book in regex_search_result {
22        println!("{:?}", book);
23    }
24
25    let field = Book::get_struct_info()
26        .generate_schema()
27        .get_field("author")
28        .unwrap();
29
30    let term = Term::from_field_text(field, "Steve Klabnik and Carol Nichols");
31    indexer.delete_using_term(term);
32    indexer.commit();
33
34    println!("After deleting");
35    let regex_search_result = indexer.hybrid_search(HashMap::new(), "name", "Rust", 10);
36    for book in regex_search_result {
37        println!("{:?}", book);
38    }
39}

Auto Trait Implementations§

§

impl<T> Freeze for Indexer<T>

§

impl<T> !RefUnwindSafe for Indexer<T>

§

impl<T> Send for Indexer<T>
where T: Send,

§

impl<T> Sync for Indexer<T>
where T: Sync,

§

impl<T> Unpin for Indexer<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Indexer<T>

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Fruit for T
where T: Send + Downcast,