query_command.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. mod common;
  2. use common::*;
  3. const COLLECTION: &str = "Search";
  4. #[test]
  5. fn should_find_object_by_exact_match() {
  6. let bucket = "query_by_exact_match";
  7. let title = "Sweet Teriyaki Beef Skewers";
  8. let dest = Dest::col_buc(COLLECTION, bucket);
  9. let ingest_channel = ingest_start();
  10. ingest_channel
  11. .push(PushRequest::new(dest.clone().obj("1"), title))
  12. .unwrap();
  13. consolidate();
  14. let search_channel = search_start();
  15. match search_channel.query(QueryRequest::new(dest, title)) {
  16. Ok(object_ids) => assert_eq!(object_ids, vec![String::from("1")]),
  17. Err(_) => unreachable!(),
  18. }
  19. flush_bucket(COLLECTION, bucket);
  20. }
  21. #[test]
  22. fn should_find_multiline_object_by_partial_match() {
  23. let bucket = "query_multiline";
  24. let multiline_text = "
  25. Sweet
  26. Teriyaki
  27. Beef
  28. Skewers
  29. None";
  30. let dest = Dest::col_buc(COLLECTION, bucket);
  31. let ingest_channel = ingest_start();
  32. ingest_channel
  33. .push(PushRequest::new(dest.clone().obj("1"), multiline_text))
  34. .unwrap();
  35. consolidate();
  36. let words = ["Sweet", "Teriyaki", "Beef", "Skewers"];
  37. let search_channel = search_start();
  38. for word in words {
  39. match search_channel.query(QueryRequest::new(dest.clone(), word)) {
  40. Ok(object_ids) => assert_eq!(object_ids, vec![String::from("1")]),
  41. Err(_) => unreachable!(),
  42. }
  43. }
  44. flush_bucket(COLLECTION, bucket);
  45. }
  46. #[test]
  47. fn should_find_many_objects() {
  48. let bucket = "query_many_objects";
  49. let dest = Dest::col_buc(COLLECTION, bucket);
  50. let ingest_channel = ingest_start();
  51. ingest_channel
  52. .push(PushRequest::new(
  53. dest.clone().obj("1"),
  54. "Sweet Teriyaki Beef Skewers",
  55. ))
  56. .unwrap();
  57. ingest_channel
  58. .push(PushRequest::new(
  59. dest.clone().obj("2"),
  60. "Slow Cooker Beef Stew I",
  61. ))
  62. .unwrap();
  63. ingest_channel
  64. .push(PushRequest::new(
  65. dest.clone().obj("3"),
  66. "Christmas Prime Rib",
  67. ))
  68. .unwrap();
  69. consolidate();
  70. let search_channel = search_start();
  71. match search_channel.query(QueryRequest::new(dest, "Beef")) {
  72. Ok(object_ids) => assert_eq!(object_ids, vec!["2", "1"]),
  73. Err(_) => unreachable!(),
  74. }
  75. flush_bucket(COLLECTION, bucket);
  76. }
  77. #[test]
  78. fn should_find_limited_objects() {
  79. let bucket = "query_limited_objects";
  80. let dest = Dest::col_buc(COLLECTION, bucket);
  81. let ingest_channel = ingest_start();
  82. ingest_channel
  83. .push(PushRequest::new(
  84. dest.clone().obj("1"),
  85. "Sweet Teriyaki Beef Skewers",
  86. ))
  87. .unwrap();
  88. ingest_channel
  89. .push(PushRequest::new(
  90. dest.clone().obj("2"),
  91. "Slow Cooker Beef Stew I",
  92. ))
  93. .unwrap();
  94. ingest_channel
  95. .push(PushRequest::new(
  96. dest.clone().obj("3"),
  97. "Christmas Prime Rib",
  98. ))
  99. .unwrap();
  100. consolidate();
  101. let search_channel = search_start();
  102. match search_channel.query(QueryRequest::new(dest.clone(), "Beef").limit(1)) {
  103. Ok(object_ids) => assert_eq!(object_ids, vec!["2"]),
  104. Err(_) => unreachable!(),
  105. }
  106. let search_channel = search_start();
  107. match search_channel.query(QueryRequest::new(dest, "Beef").pag(1, 1)) {
  108. Ok(object_ids) => assert_eq!(object_ids, vec!["1"]),
  109. Err(_) => unreachable!(),
  110. }
  111. flush_bucket(COLLECTION, bucket);
  112. }