-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// use search::index::Index; | ||
use search::query::QueryProcessor; | ||
use std::io::{self, Write}; | ||
|
||
const NUM_RESULTS: usize = 10; | ||
|
||
fn print_results(results: &[u32]) { | ||
println!("\nSearch Results:"); | ||
for (i, doc_id) in results.iter().enumerate() { | ||
println!("\t- {:3}. Doc ID: {}", i + 1, doc_id); | ||
} | ||
println!(); | ||
} | ||
|
||
fn read_line(prompt: &str) -> String { | ||
print!("{}", prompt); | ||
io::stdout().flush().unwrap(); | ||
|
||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).unwrap(); | ||
input.trim().to_string() | ||
} | ||
|
||
fn main() { | ||
let base_path = "data/wiki-data"; | ||
let index_path = base_path.to_string() + "/index/index"; | ||
let tokenizer_path = base_path.to_string() + "/tokenizer/bert-base-uncased"; | ||
|
||
// let docs_path = base_path.to_string() + "/docs"; | ||
// Index::build_index(&docs_path, &index_path, &tokenizer_path); | ||
|
||
println!( | ||
"Search engine for base path: [{}]\nWrite a query and press enter.\n", | ||
base_path | ||
); | ||
|
||
let mut q = QueryProcessor::build_query_processor(&index_path, &tokenizer_path); | ||
|
||
loop { | ||
let query = read_line("> "); | ||
|
||
// Perform search | ||
let results = q.query(&query, NUM_RESULTS); | ||
|
||
// Display results | ||
print_results(&results); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters