in components/suggest/src/store.rs [1736:2252]
fn query() -> anyhow::Result<()> {
before_each();
let store = TestStore::new(
MockRemoteSettingsClient::default()
.with_record(
SuggestionProvider::Amp.record("data-1", json!([good_place_eats_amp(),])),
)
.with_record(SuggestionProvider::Wikipedia.record(
"wikipedia-1",
json!([california_wiki(), caltech_wiki(), multimatch_wiki(),]),
))
.with_record(
SuggestionProvider::Amo
.record("data-2", json!([relay_amo(), multimatch_amo(),])),
)
.with_record(
SuggestionProvider::Pocket
.record("data-3", json!([burnout_pocket(), multimatch_pocket(),])),
)
.with_record(SuggestionProvider::Yelp.record("data-4", json!([ramen_yelp(),])))
.with_record(SuggestionProvider::Mdn.record("data-5", json!([array_mdn(),])))
.with_record(SuggestionProvider::Amp.icon(good_place_eats_icon()))
.with_record(SuggestionProvider::Wikipedia.icon(california_icon()))
.with_record(SuggestionProvider::Wikipedia.icon(caltech_icon()))
.with_record(SuggestionProvider::Yelp.icon(yelp_favicon()))
.with_record(SuggestionProvider::Wikipedia.icon(multimatch_wiki_icon())),
);
store.ingest(SuggestIngestionConstraints::all_providers());
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers("")),
vec![]
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers("la")),
vec![good_place_eats_suggestion("lasagna", None),]
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers("multimatch")),
vec![
multimatch_pocket_suggestion(true),
multimatch_amo_suggestion(),
multimatch_wiki_suggestion(),
]
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers("MultiMatch")),
vec![
multimatch_pocket_suggestion(true),
multimatch_amo_suggestion(),
multimatch_wiki_suggestion(),
]
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers("multimatch").limit(2)),
vec![
multimatch_pocket_suggestion(true),
multimatch_amo_suggestion(),
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::amp("la")),
vec![good_place_eats_suggestion("lasagna", None)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::all_providers_except(
"la",
SuggestionProvider::Amp
)),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::with_providers("la", vec![])),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::with_providers(
"cal",
vec![
SuggestionProvider::Amp,
SuggestionProvider::Amo,
SuggestionProvider::Pocket,
]
)),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::wikipedia("cal")),
vec![
california_suggestion("california"),
caltech_suggestion("california"),
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::wikipedia("cal").limit(1)),
vec![california_suggestion("california"),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::with_providers("cal", vec![])),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::amo("spam")),
vec![relay_suggestion()],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::amo("masking")),
vec![relay_suggestion()],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::amo("masking e")),
vec![relay_suggestion()],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::amo("masking s")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::with_providers(
"soft",
vec![SuggestionProvider::Amp, SuggestionProvider::Wikipedia]
)),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::pocket("soft")),
vec![burnout_suggestion(false),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::pocket("soft l")),
vec![burnout_suggestion(false),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::pocket("sof")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::pocket("burnout women")),
vec![burnout_suggestion(true),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::pocket("burnout person")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best spicy ramen delivery in tokyo")),
vec![ramen_suggestion(
"best spicy ramen delivery in tokyo",
"https://www.yelp.com/search?find_desc=best+spicy+ramen+delivery&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("BeSt SpIcY rAmEn DeLiVeRy In ToKyO")),
vec![ramen_suggestion(
"BeSt SpIcY rAmEn DeLiVeRy In ToKyO",
"https://www.yelp.com/search?find_desc=BeSt+SpIcY+rAmEn+DeLiVeRy&find_loc=ToKyO"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best ramen delivery in tokyo")),
vec![ramen_suggestion(
"best ramen delivery in tokyo",
"https://www.yelp.com/search?find_desc=best+ramen+delivery&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp(
"best invalid_ramen delivery in tokyo"
)),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best in tokyo")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("super best ramen in tokyo")),
vec![ramen_suggestion(
"super best ramen in tokyo",
"https://www.yelp.com/search?find_desc=super+best+ramen&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("invalid_best ramen in tokyo")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen delivery in tokyo")),
vec![ramen_suggestion(
"ramen delivery in tokyo",
"https://www.yelp.com/search?find_desc=ramen+delivery&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen super delivery in tokyo")),
vec![ramen_suggestion(
"ramen super delivery in tokyo",
"https://www.yelp.com/search?find_desc=ramen+super+delivery&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen invalid_delivery")),
vec![ramen_suggestion(
"ramen invalid_delivery",
"https://www.yelp.com/search?find_desc=ramen&find_loc=invalid_delivery"
)
.has_location_sign(false),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen invalid_delivery in tokyo")),
vec![ramen_suggestion(
"ramen invalid_delivery in tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=invalid_delivery+in+tokyo"
)
.has_location_sign(false),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen in tokyo")),
vec![ramen_suggestion(
"ramen in tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen near tokyo")),
vec![ramen_suggestion(
"ramen near tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen invalid_in tokyo")),
vec![ramen_suggestion(
"ramen invalid_in tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=invalid_in+tokyo"
)
.has_location_sign(false),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen in San Francisco")),
vec![ramen_suggestion(
"ramen in San Francisco",
"https://www.yelp.com/search?find_desc=ramen&find_loc=San+Francisco"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen in")),
vec![ramen_suggestion(
"ramen in",
"https://www.yelp.com/search?find_desc=ramen"
),],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen near by")),
vec![ramen_suggestion(
"ramen near by",
"https://www.yelp.com/search?find_desc=ramen"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen near me")),
vec![ramen_suggestion(
"ramen near me",
"https://www.yelp.com/search?find_desc=ramen"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen near by tokyo")),
vec![ramen_suggestion(
"ramen near by tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false),
],
);
// Test an extremely long yelp query
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
)),
vec![
ramen_suggestion(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"https://www.yelp.com/search?find_desc=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
).has_location_sign(false),
],
);
// This query is over the limit and no suggestions should be returned
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789Z"
)),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best delivery")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("same_modifier same_modifier")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("same_modifier ")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("yelp ramen")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false),
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("yelp keyword ramen")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false),
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen in tokyo yelp")),
vec![ramen_suggestion(
"ramen in tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen in tokyo yelp keyword")),
vec![ramen_suggestion(
"ramen in tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("yelp ramen yelp")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false)
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best yelp ramen")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("Spicy R")),
vec![ramen_suggestion(
"Spicy Ramen",
"https://www.yelp.com/search?find_desc=Spicy+Ramen"
)
.has_location_sign(false)
.subject_exact_match(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("spi")),
vec![ramen_suggestion(
"spicy ramen",
"https://www.yelp.com/search?find_desc=spicy+ramen"
)
.has_location_sign(false)
.subject_exact_match(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("BeSt Ramen")),
vec![ramen_suggestion(
"BeSt Ramen",
"https://www.yelp.com/search?find_desc=BeSt+Ramen"
)
.has_location_sign(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("BeSt Spicy R")),
vec![ramen_suggestion(
"BeSt Spicy Ramen",
"https://www.yelp.com/search?find_desc=BeSt+Spicy+Ramen"
)
.has_location_sign(false)
.subject_exact_match(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("BeSt R")),
vec![],
);
assert_eq!(store.fetch_suggestions(SuggestionQuery::yelp("r")), vec![],);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ra")),
vec![
ramen_suggestion("rats", "https://www.yelp.com/search?find_desc=rats")
.has_location_sign(false)
.subject_exact_match(false)
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ram")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false)
.subject_exact_match(false)
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("rac")),
vec![
ramen_suggestion("raccoon", "https://www.yelp.com/search?find_desc=raccoon")
.has_location_sign(false)
.subject_exact_match(false)
],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best r")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best ra")),
vec![ramen_suggestion(
"best rats",
"https://www.yelp.com/search?find_desc=best+rats"
)
.has_location_sign(false)
.subject_exact_match(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best sp")),
vec![ramen_suggestion(
"best spicy ramen",
"https://www.yelp.com/search?find_desc=best+spicy+ramen"
)
.has_location_sign(false)
.subject_exact_match(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramenabc")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramenabc xyz")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best ramenabc")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("bestabc ra")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("bestabc ramen")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("bestabc ramen xyz")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("best spi ram")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("bes ram")),
vec![],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("bes ramen")),
vec![],
);
// Test for prefix match.
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen D")),
vec![ramen_suggestion(
"ramen Delivery",
"https://www.yelp.com/search?find_desc=ramen+Delivery"
)
.has_location_sign(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen I")),
vec![ramen_suggestion(
"ramen In",
"https://www.yelp.com/search?find_desc=ramen"
)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen Y")),
vec![
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
.has_location_sign(false)
],
);
// Prefix match is available only for last words.
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen D Yelp")),
vec![ramen_suggestion(
"ramen D",
"https://www.yelp.com/search?find_desc=ramen&find_loc=D"
)
.has_location_sign(false)],
);
assert_eq!(
store.fetch_suggestions(SuggestionQuery::yelp("ramen I Tokyo")),
vec![ramen_suggestion(
"ramen I Tokyo",
"https://www.yelp.com/search?find_desc=ramen&find_loc=I+Tokyo"
)
.has_location_sign(false)],
);
Ok(())
}