|
@@ -4,6 +4,7 @@ use std::str::FromStr; |
|
|
use std::convert::From; |
|
|
use std::convert::From; |
|
|
use std::path::Path; |
|
|
use std::path::Path; |
|
|
use std::path::PathBuf; |
|
|
use std::path::PathBuf; |
|
|
|
|
|
use std::io::Write; |
|
|
use tantivy; |
|
|
use tantivy; |
|
|
use tantivy::query::QueryParser; |
|
|
use tantivy::query::QueryParser; |
|
|
use tantivy::schema::Field; |
|
|
use tantivy::schema::Field; |
|
@@ -47,6 +48,9 @@ fn run_search(directory: &Path, query: &str) -> tantivy::Result<()> { |
|
|
let searcher = index.reader()?.searcher(); |
|
|
let searcher = index.reader()?.searcher(); |
|
|
let weight = query.weight(&searcher, false)?; |
|
|
let weight = query.weight(&searcher, false)?; |
|
|
let schema = index.schema(); |
|
|
let schema = index.schema(); |
|
|
|
|
|
let stdout = std::io::stdout(); |
|
|
|
|
|
let handle = stdout.lock(); |
|
|
|
|
|
let mut wtr = std::io::BufWriter::new(handle); |
|
|
for segment_reader in searcher.segment_readers() { |
|
|
for segment_reader in searcher.segment_readers() { |
|
|
let mut scorer = weight.scorer(segment_reader, 1.0)?; |
|
|
let mut scorer = weight.scorer(segment_reader, 1.0)?; |
|
|
let store_reader = segment_reader.get_store_reader(); |
|
|
let store_reader = segment_reader.get_store_reader(); |
|
@@ -54,7 +58,8 @@ fn run_search(directory: &Path, query: &str) -> tantivy::Result<()> { |
|
|
let doc_id = scorer.doc(); |
|
|
let doc_id = scorer.doc(); |
|
|
let doc = store_reader.get(doc_id)?; |
|
|
let doc = store_reader.get(doc_id)?; |
|
|
let named_doc = schema.to_named_doc(&doc); |
|
|
let named_doc = schema.to_named_doc(&doc); |
|
|
println!("{}", serde_json::to_string(&named_doc).unwrap()); |
|
|
|
|
|
|
|
|
serde_json::to_writer(&mut wtr, &named_doc).unwrap(); |
|
|
|
|
|
wtr.write_all(b"\n")?; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
Ok(()) |
|
|
Ok(()) |
|
|