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.

135 lines
4.5KB

  1. #[macro_use]
  2. extern crate clap;
  3. #[macro_use]
  4. extern crate version;
  5. #[macro_use]
  6. extern crate rustc_serialize;
  7. #[macro_use]
  8. extern crate log;
  9. extern crate env_logger;
  10. extern crate tantivy;
  11. extern crate time;
  12. extern crate persistent;
  13. extern crate urlencoded;
  14. extern crate iron;
  15. extern crate chan;
  16. extern crate staticfile;
  17. extern crate ansi_term;
  18. extern crate mount;
  19. extern crate bincode;
  20. extern crate byteorder;
  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(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. )
  81. .subcommand(
  82. SubCommand::with_name("search")
  83. .about("Search an index.")
  84. .arg(index_arg.clone())
  85. .arg(Arg::with_name("query")
  86. .short("q")
  87. .long("query")
  88. .value_name("query")
  89. .help("Query")
  90. .required(true))
  91. )
  92. .subcommand(
  93. SubCommand::with_name("bench")
  94. .about("Run a benchmark on your index")
  95. .arg(index_arg.clone())
  96. .arg(Arg::with_name("queries")
  97. .short("q")
  98. .long("queries")
  99. .value_name("queries")
  100. .help("File containing queries (one per line) to run in the benchmark.")
  101. .required(true))
  102. .arg(Arg::with_name("num_repeat")
  103. .short("n")
  104. .long("num_repeat")
  105. .value_name("num_repeat")
  106. .help("Number of times to repeat the benchmark.")
  107. .default_value("1"))
  108. )
  109. .subcommand(
  110. SubCommand::with_name("merge")
  111. .about("Merge all the segments of an index")
  112. .arg(index_arg.clone())
  113. )
  114. .get_matches();
  115. let (subcommand, some_options) = cli_options.subcommand();
  116. let options = some_options.unwrap();
  117. let run_cli = match subcommand {
  118. "new" => run_new_cli,
  119. "index" => run_index_cli,
  120. "serve" => run_serve_cli,
  121. "search" => run_search_cli,
  122. "merge" => run_merge_cli,
  123. "bench" => run_bench_cli,
  124. _ => panic!("Subcommand {} is unknown", subcommand)
  125. };
  126. run_cli(options).unwrap();
  127. }