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.

121 lines
4.1KB

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