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.

141 lines
4.7KB

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