You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.8KB

  1. #[macro_use]
  2. extern crate clap;
  3. #[macro_use]
  4. extern crate rustc_serialize;
  5. extern crate tantivy;
  6. extern crate time;
  7. extern crate persistent;
  8. extern crate urlencoded;
  9. extern crate iron;
  10. extern crate staticfile;
  11. extern crate ansi_term;
  12. extern crate mount;
  13. use clap::{AppSettings, Arg, App, SubCommand};
  14. mod commands;
  15. use self::commands::*;
  16. fn main() {
  17. let index_arg = Arg::with_name("index")
  18. .short("i")
  19. .long("index")
  20. .value_name("directory")
  21. .help("Tantivy index directory filepath")
  22. .required(true);
  23. let cli_options = App::new("Tantivy")
  24. .setting(AppSettings::SubcommandRequiredElseHelp)
  25. .version("0.1")
  26. .author("Paul Masurel <paul.masurel@gmail.com>")
  27. .about("Tantivy Search Engine's command line interface.")
  28. .subcommand(
  29. SubCommand::with_name("new")
  30. .about("Create a new index. The schema will be populated with a simple example schema")
  31. .arg(index_arg.clone())
  32. )
  33. .subcommand(
  34. SubCommand::with_name("serve")
  35. .about("Start a server")
  36. .arg(index_arg.clone())
  37. .arg(Arg::with_name("host")
  38. .long("host")
  39. .value_name("host")
  40. .help("host to listen to")
  41. )
  42. .arg(Arg::with_name("port")
  43. .short("p")
  44. .long("port")
  45. .value_name("port")
  46. .help("Port")
  47. .default_value("localhost")
  48. )
  49. )
  50. .subcommand(
  51. SubCommand::with_name("index")
  52. .about("Index files")
  53. .arg(index_arg.clone())
  54. .arg(Arg::with_name("file")
  55. .short("f")
  56. .long("file")
  57. .value_name("file")
  58. .help("File containing the documents to index."))
  59. .arg(Arg::with_name("num_threads")
  60. .short("t")
  61. .long("num_threads")
  62. .value_name("num_threads")
  63. .help("Number of indexing thread. By default num cores - 1 will be used")
  64. .default_value("0"))
  65. )
  66. .subcommand(
  67. SubCommand::with_name("bench")
  68. .about("Run a benchmark on your index")
  69. .arg(index_arg.clone())
  70. .arg(Arg::with_name("queries")
  71. .short("q")
  72. .long("queries")
  73. .value_name("queries")
  74. .help("File containing queries (one-per line) to run in the benchmark.")
  75. .required(true))
  76. .arg(Arg::with_name("num_repeat")
  77. .short("n")
  78. .long("num_repeat")
  79. .value_name("num_repeat")
  80. .help("Number of time to repeat the benchmark.")
  81. .default_value("1"))
  82. )
  83. .subcommand(
  84. SubCommand::with_name("merge")
  85. .about("Merge all the segments of an index")
  86. .arg(index_arg.clone())
  87. )
  88. .get_matches();
  89. let (subcommand, some_options) = cli_options.subcommand();
  90. let options = some_options.unwrap();
  91. match subcommand {
  92. "new" => run_new_cli(options).unwrap(),
  93. "index" => run_index_cli(options).unwrap(),
  94. "serve" => run_serve_cli(options).unwrap(),
  95. "merge" => run_merge_cli(options).unwrap(),
  96. "bench" => {
  97. let res = run_bench_cli(options);
  98. match res {
  99. Err(e) => { println!("{}", e);}
  100. _ => {}
  101. }
  102. },
  103. _ => {}
  104. }
  105. }