Skip to content

Commit

Permalink
Merge 8fd30ac into 550d601
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Aug 19, 2022
2 parents 550d601 + 8fd30ac commit 304c56e
Show file tree
Hide file tree
Showing 14 changed files with 605 additions and 722 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
Cargo.lock
*.bak
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ See [recipe search demo project](https://github.com/quantleaf/probly-search-demo
```rust
use std::collections::HashSet;
use probly_search::{
index::{add_document_to_index, create_index, remove_document_from_index, Index},
index::Index,
query::{
query,
score::default::{bm25, zero_to_one},
QueryResult,
},
Expand Down Expand Up @@ -70,9 +69,8 @@ fn filter(s: &str) -> &str {
s
}


// Create index with 2 fields
let mut index = create_index::<usize>(2);
let mut index = Index::<usize>::new(2);

// Create docs from a custom Doc struct
let doc_1 = Doc {
Expand All @@ -88,17 +86,15 @@ let doc_2 = Doc {
};

// Add documents to index
add_document_to_index(
&mut index,
index.add_document(
&[title_extract, description_extract],
tokenizer,
filter,
doc_1.id,
&doc_1,
);

add_document_to_index(
&mut index,
index.add_document(
&[title_extract, description_extract],
tokenizer,
filter,
Expand All @@ -107,8 +103,7 @@ add_document_to_index(
);

// Search, expected 2 results
let mut result = query(
&mut index,
let mut result = index.query(
&"abc",
&mut bm25::new(),
tokenizer,
Expand All @@ -134,14 +129,13 @@ assert_eq!(

// Remove documents from index
let mut removed_docs = HashSet::new();
remove_document_from_index(&mut index, &mut removed_docs, doc_1.id);
index.remove_document(&mut removed_docs, doc_1.id);

// Vacuum to remove completely
vacuum_index(&mut index, &mut removed_docs);
index.vacuum(&mut removed_docs);

// Search, expect 1 result
result = query(
&mut index,
result = index.query(
&"abc",
&mut bm25::new(),
tokenizer,
Expand Down
8 changes: 4 additions & 4 deletions benches/test_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, Criterion};
use probly_search::index::{add_document_to_index, create_index_with_capacity, Index};
use probly_search::Index;

criterion_group!(benches, test_speed);
criterion_main!(benches);
Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn test_speed(c: &mut Criterion) {
}

c.bench_function("add_100k_docs", |b| {
let mut index = create_index_with_capacity(1, 100000, 100000);
let mut index = Index::<usize>::new_with_capacity(1, 100000, 100000);
let mut random_strings: Vec<String> = Vec::new();
for _ in 1..100000 {
let mut new_rand = generate_string(0, 4);
Expand All @@ -51,7 +51,7 @@ pub fn test_speed(c: &mut Criterion) {
}

fn add_all_documents(
mut index: &mut Index<usize>,
index: &mut Index<usize>,
extractor: &[fn(&DocX) -> Option<&str>],
random_strings: &[String],
) {
Expand All @@ -60,6 +60,6 @@ fn add_all_documents(
id: i,
title: s.to_owned(),
};
add_document_to_index(&mut index, extractor, tokenizer, filter, d.id, &d);
index.add_document(extractor, tokenizer, filter, d.id, &d);
}
}
Loading

0 comments on commit 304c56e

Please sign in to comment.