2021-12-24 17:15:51 +03:00
|
|
|
mod common;
|
|
|
|
use common::*;
|
|
|
|
|
|
|
|
const COLLECTION: &str = "Search";
|
|
|
|
|
|
|
|
#[test]
|
2021-12-24 23:43:47 +03:00
|
|
|
fn should_find_object_by_exact_match() {
|
|
|
|
let bucket = "query_by_exact_match";
|
2021-12-24 17:15:51 +03:00
|
|
|
let title = "Sweet Teriyaki Beef Skewers";
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
let dest = Dest::col_buc(COLLECTION, bucket);
|
2021-12-24 17:15:51 +03:00
|
|
|
|
|
|
|
let ingest_channel = ingest_start();
|
2021-12-24 23:49:04 +03:00
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(dest.clone().obj("1"), title))
|
2021-12-24 23:49:04 +03:00
|
|
|
.unwrap();
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
consolidate();
|
2021-12-24 23:49:04 +03:00
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
let search_channel = search_start();
|
|
|
|
match search_channel.query(QueryRequest::new(dest, title)) {
|
|
|
|
Ok(object_ids) => assert_eq!(object_ids, vec![String::from("1")]),
|
|
|
|
Err(_) => unreachable!(),
|
2021-12-24 23:49:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
flush_bucket(COLLECTION, bucket);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_find_multiline_object_by_partial_match() {
|
|
|
|
let bucket = "query_multiline";
|
|
|
|
let multiline_text = "
|
|
|
|
Sweet
|
|
|
|
Teriyaki
|
|
|
|
Beef
|
|
|
|
Skewers
|
2022-07-18 14:07:12 +03:00
|
|
|
None";
|
|
|
|
|
|
|
|
let dest = Dest::col_buc(COLLECTION, bucket);
|
2021-12-24 23:49:04 +03:00
|
|
|
|
|
|
|
let ingest_channel = ingest_start();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(dest.clone().obj("1"), multiline_text))
|
2021-12-24 23:49:04 +03:00
|
|
|
.unwrap();
|
2021-12-24 17:15:51 +03:00
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
consolidate();
|
2021-12-24 17:15:51 +03:00
|
|
|
|
2021-12-24 23:49:04 +03:00
|
|
|
let words = ["Sweet", "Teriyaki", "Beef", "Skewers"];
|
2022-07-18 14:07:12 +03:00
|
|
|
let search_channel = search_start();
|
2021-12-24 23:49:04 +03:00
|
|
|
for word in words {
|
2022-07-18 14:07:12 +03:00
|
|
|
match search_channel.query(QueryRequest::new(dest.clone(), word)) {
|
|
|
|
Ok(object_ids) => assert_eq!(object_ids, vec![String::from("1")]),
|
2021-12-24 17:15:51 +03:00
|
|
|
Err(_) => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 23:43:47 +03:00
|
|
|
flush_bucket(COLLECTION, bucket);
|
2021-12-24 17:15:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_find_many_objects() {
|
2021-12-24 23:43:47 +03:00
|
|
|
let bucket = "query_many_objects";
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
let dest = Dest::col_buc(COLLECTION, bucket);
|
|
|
|
|
2021-12-24 17:15:51 +03:00
|
|
|
let ingest_channel = ingest_start();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("1"),
|
|
|
|
"Sweet Teriyaki Beef Skewers",
|
|
|
|
))
|
2021-12-24 17:15:51 +03:00
|
|
|
.unwrap();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("2"),
|
|
|
|
"Slow Cooker Beef Stew I",
|
|
|
|
))
|
2021-12-24 17:15:51 +03:00
|
|
|
.unwrap();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("3"),
|
|
|
|
"Christmas Prime Rib",
|
|
|
|
))
|
2021-12-24 17:15:51 +03:00
|
|
|
.unwrap();
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
consolidate();
|
|
|
|
|
2021-12-24 17:15:51 +03:00
|
|
|
let search_channel = search_start();
|
2022-07-18 14:07:12 +03:00
|
|
|
match search_channel.query(QueryRequest::new(dest, "Beef")) {
|
2021-12-24 17:15:51 +03:00
|
|
|
Ok(object_ids) => assert_eq!(object_ids, vec!["2", "1"]),
|
|
|
|
Err(_) => unreachable!(),
|
|
|
|
}
|
2021-12-24 17:25:31 +03:00
|
|
|
|
2021-12-24 23:43:47 +03:00
|
|
|
flush_bucket(COLLECTION, bucket);
|
2021-12-24 17:15:51 +03:00
|
|
|
}
|
2021-12-25 00:24:20 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_find_limited_objects() {
|
|
|
|
let bucket = "query_limited_objects";
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
let dest = Dest::col_buc(COLLECTION, bucket);
|
|
|
|
|
2021-12-25 00:24:20 +03:00
|
|
|
let ingest_channel = ingest_start();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("1"),
|
|
|
|
"Sweet Teriyaki Beef Skewers",
|
|
|
|
))
|
2021-12-25 00:24:20 +03:00
|
|
|
.unwrap();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("2"),
|
|
|
|
"Slow Cooker Beef Stew I",
|
|
|
|
))
|
2021-12-25 00:24:20 +03:00
|
|
|
.unwrap();
|
|
|
|
ingest_channel
|
2022-07-18 14:07:12 +03:00
|
|
|
.push(PushRequest::new(
|
|
|
|
dest.clone().obj("3"),
|
|
|
|
"Christmas Prime Rib",
|
|
|
|
))
|
2021-12-25 00:24:20 +03:00
|
|
|
.unwrap();
|
|
|
|
|
2022-07-18 14:07:12 +03:00
|
|
|
consolidate();
|
|
|
|
|
2021-12-25 00:24:20 +03:00
|
|
|
let search_channel = search_start();
|
2022-07-18 14:07:12 +03:00
|
|
|
match search_channel.query(QueryRequest::new(dest.clone(), "Beef").limit(1)) {
|
2021-12-25 00:24:20 +03:00
|
|
|
Ok(object_ids) => assert_eq!(object_ids, vec!["2"]),
|
|
|
|
Err(_) => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
let search_channel = search_start();
|
2022-07-18 14:07:12 +03:00
|
|
|
match search_channel.query(QueryRequest::new(dest, "Beef").pag(1, 1)) {
|
2021-12-25 00:24:20 +03:00
|
|
|
Ok(object_ids) => assert_eq!(object_ids, vec!["1"]),
|
|
|
|
Err(_) => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
flush_bucket(COLLECTION, bucket);
|
|
|
|
}
|