Commit 0db900b9 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Initial commit

Pipeline #43 failed with stages
in 16 seconds
This diff is collapsed.
name = "dfih-search"
version = "0.1.0"
authors = ["Emmanuel Raviart <>"]
json = "0.11"
tantivy = "0.7"
// #[macro_use]
extern crate json;
extern crate tantivy;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::Path;
use tantivy::collector::TopCollector;
use tantivy::query::QueryParser;
use tantivy::schema::*;
use tantivy::Index;
fn main() -> tantivy::Result<()> {
let data_dir = Path::new("../dfih-ui/data");
let index_dir = data_dir.join("index");
let mut schema_builder = SchemaBuilder::default();
schema_builder.add_text_field("name", TEXT | STORED);
let schema =;
let index = Index::create_in_dir(&index_dir, schema.clone())?;
let mut index_writer = index.writer(50_000_000)?;
let issuers_dir = data_dir.join("issuers");
let name_field = schema.get_field("name").unwrap();
for entry in fs::read_dir(issuers_dir).unwrap() {
let json_file_path = entry.unwrap().path();
let mut json_file = File::open(json_file_path).expect("JSON file not found");
let mut json_string = String::new();
.read_to_string(&mut json_string)
.expect("Something went wrong reading the file");
let issuer = json::parse(&json_string).expect("Invalid JSON");
let mut issuer_doc = Document::default();
for name in issuer["names"].members() {
println!("{}", name);
issuer_doc.add_text(name_field, &name.to_string());
let searcher = index.searcher();
let query_parser = QueryParser::for_index(&index, vec![name_field]);
let query = query_parser.parse_query("forges")?;
let mut top_collector = TopCollector::with_limit(10);*query, &mut top_collector)?;
let doc_addresses =;
for doc_address in doc_addresses {
let retrieved_doc = searcher.doc(doc_address)?;
println!("{}", schema.to_json(&retrieved_doc));
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment