|
|
@@ -10,6 +10,8 @@ use tantivy; |
|
|
|
use tantivy::schema::Cardinality; |
|
|
|
use tantivy::schema::*; |
|
|
|
use tantivy::Index; |
|
|
|
use std::fs; |
|
|
|
|
|
|
|
|
|
|
|
pub fn run_new_cli(matches: &ArgMatches) -> Result<(), String> { |
|
|
|
let index_directory = PathBuf::from(matches.value_of("index").unwrap()); |
|
|
@@ -152,6 +154,12 @@ fn run_new(directory: PathBuf) -> tantivy::Result<()> { |
|
|
|
let schema = schema_builder.build(); |
|
|
|
let schema_json = format!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
|
|
|
println!("\n{}\n", Style::new().fg(Green).paint(schema_json)); |
|
|
|
match fs::create_dir(&directory) { |
|
|
|
Ok(_) => (), |
|
|
|
// Proceed here; actual existence of index is checked in Index::create_in_dir |
|
|
|
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => (), |
|
|
|
Err(e) => panic!("{:?}", e), |
|
|
|
}; |
|
|
|
Index::create_in_dir(&directory, schema)?; |
|
|
|
Ok(()) |
|
|
|
} |