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.

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