diff --git a/components/suggest/src/db.rs b/components/suggest/src/db.rs index d20373d7c51..982f7ffc641 100644 --- a/components/suggest/src/db.rs +++ b/components/suggest/src/db.rs @@ -27,7 +27,7 @@ use crate::{ }, schema::{SuggestConnectionInitializer, VERSION}, store::{UnparsableRecord, UnparsableRecords}, - suggestion::{cook_raw_suggestion_url, AmpSuggestionType, Suggestion}, + suggestion::{cook_raw_suggestion_url, AmpSuggestionType, Suggestion, SuggestionIcon}, Result, SuggestionQuery, }; @@ -290,7 +290,7 @@ impl<'a> SuggestDao<'a> { amp.iab_category, amp.impression_url, amp.click_url, - i.data AS icon, + i.data AS icon_content, i.mimetype AS icon_mimetype FROM amp_custom_details amp @@ -306,6 +306,13 @@ impl<'a> SuggestDao<'a> { let cooked_url = cook_raw_suggestion_url(&raw_url); let raw_click_url = row.get::<_, String>("click_url")?; let cooked_click_url = cook_raw_suggestion_url(&raw_click_url); + let icon = match row.get("icon_content")? { + Some(content) => Some(SuggestionIcon { + content, + mime_type: row.get("icon_mimetype")?, + }), + _ => None, + }; Ok(Suggestion::Amp { block_id: row.get("block_id")?, @@ -316,8 +323,7 @@ impl<'a> SuggestDao<'a> { raw_url, full_keyword: full_keyword_from_db .unwrap_or_else(|| full_keyword(keyword_lowercased, &keywords)), - icon: row.get("icon")?, - icon_mimetype: row.get("icon_mimetype")?, + icon, impression_url: row.get("impression_url")?, click_url: cooked_click_url, raw_click_url, @@ -368,7 +374,7 @@ impl<'a> SuggestDao<'a> { }, |row| row.get(0), )?; - let (icon, icon_mimetype) = self + let icon = self .conn .try_query_row( "SELECT i.data, i.mimetype @@ -380,21 +386,20 @@ impl<'a> SuggestDao<'a> { ":suggestion_id": suggestion_id }, |row| -> Result<_> { - Ok(( - row.get::<_, Option>>(0)?, - row.get::<_, Option>(1)?, - )) + Ok(Some(SuggestionIcon { + content: row.get::<_, Vec>(0)?, + mime_type: row.get::<_, String>(1)?, + })) }, true, )? - .unwrap_or((None, None)); + .unwrap_or(None); Ok(Suggestion::Wikipedia { title, url: raw_url, full_keyword: full_keyword(keyword_lowercased, &keywords), icon, - icon_mimetype, }) }, )?; diff --git a/components/suggest/src/lib.rs b/components/suggest/src/lib.rs index 23775b7decb..7260445b893 100644 --- a/components/suggest/src/lib.rs +++ b/components/suggest/src/lib.rs @@ -20,7 +20,7 @@ pub use config::{SuggestGlobalConfig, SuggestProviderConfig}; pub use error::SuggestApiError; pub use provider::SuggestionProvider; pub use store::{SuggestIngestionConstraints, SuggestStore, SuggestStoreBuilder}; -pub use suggestion::{raw_suggestion_url_matches, Suggestion}; +pub use suggestion::{raw_suggestion_url_matches, Suggestion, SuggestionIcon}; pub(crate) type Result = std::result::Result; pub type SuggestApiResult = std::result::Result; diff --git a/components/suggest/src/store.rs b/components/suggest/src/store.rs index 6b9b1231335..fb289138313 100644 --- a/components/suggest/src/store.rs +++ b/components/suggest/src/store.rs @@ -825,7 +825,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -916,23 +915,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 105, - 45, - 97, - 109, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -957,23 +956,23 @@ mod tests { url: "https://penne.biz", raw_url: "https://penne.biz", icon: Some( - [ - 105, - 45, - 97, - 109, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "penne", block_id: 0, @@ -1138,7 +1137,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los pollos", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -1153,7 +1151,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los", block_id: 1, advertiser: "Los Pollos Hermanos", @@ -1178,7 +1175,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los pollos hermanos (restaurant)", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -1193,7 +1189,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los pollos hermanos", block_id: 1, advertiser: "Los Pollos Hermanos", @@ -1217,7 +1212,6 @@ mod tests { title: "Los Pollos Hermanos - Albuquerque - Wiki", url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los", }, ] @@ -1235,7 +1229,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los pollos hermanos (restaurant)", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -1305,7 +1298,6 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: None, - icon_mimetype: None, full_keyword: "lasagna", block_id: 0, advertiser: "Good Place Eats", @@ -1394,7 +1386,6 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: None, - icon_mimetype: None, full_keyword: "lasagna", block_id: 0, advertiser: "Good Place Eats", @@ -1480,7 +1471,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los pollos", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -1504,7 +1494,6 @@ mod tests { url: "https://penne.biz", raw_url: "https://penne.biz", icon: None, - icon_mimetype: None, full_keyword: "penne", block_id: 0, advertiser: "Good Place Eats", @@ -1655,27 +1644,27 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 110, - 101, - 119, - 45, - 108, - 97, - 115, - 97, - 103, - 110, - 97, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 110, + 101, + 119, + 45, + 108, + 97, + 115, + 97, + 103, + 110, + 97, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -1700,26 +1689,26 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: Some( - [ - 110, - 101, - 119, - 45, - 112, - 111, - 108, - 108, - 111, - 115, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 110, + 101, + 119, + 45, + 112, + 111, + 108, + 108, + 111, + 115, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "los", block_id: 0, @@ -2493,23 +2482,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 105, - 45, - 97, - 109, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -2559,23 +2548,23 @@ mod tests { title: "Multimatch", url: "https://wikipedia.org/Multimatch", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "multimatch", }, @@ -2618,23 +2607,23 @@ mod tests { title: "Multimatch", url: "https://wikipedia.org/Multimatch", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "multimatch", }, @@ -2690,23 +2679,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 105, - 45, - 97, - 109, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -2774,23 +2763,23 @@ mod tests { title: "California", url: "https://wikipedia.org/California", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -2798,23 +2787,23 @@ mod tests { title: "California Institute of Technology", url: "https://wikipedia.org/California_Institute_of_Technology", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -2834,23 +2823,23 @@ mod tests { title: "California", url: "https://wikipedia.org/California", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -3051,20 +3040,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=best+spicy+ramen+delivery&find_loc=tokyo", title: "best spicy ramen delivery in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3087,20 +3076,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=BeSt+SpIcY+rAmEn+DeLiVeRy&find_loc=ToKyO", title: "BeSt SpIcY rAmEn DeLiVeRy In ToKyO", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3123,20 +3112,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=best+ramen+delivery&find_loc=tokyo", title: "best ramen delivery in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3181,20 +3170,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=super+best+ramen+delivery&find_loc=tokyo", title: "super best ramen delivery in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3228,20 +3217,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+delivery&find_loc=tokyo", title: "ramen delivery in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3264,20 +3253,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+super+delivery&find_loc=tokyo", title: "ramen super delivery in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3311,20 +3300,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3347,20 +3336,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen near tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3394,20 +3383,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=San+Francisco", title: "ramen in San Francisco", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3430,20 +3419,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen in", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3466,20 +3455,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+near+by", title: "ramen near by", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3502,20 +3491,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+near+me", title: "ramen near me", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3549,20 +3538,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3585,20 +3574,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", title: "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3665,20 +3654,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3701,20 +3690,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3737,20 +3726,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3773,20 +3762,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen in tokyo", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3809,20 +3798,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3856,20 +3845,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=Spicy+Ramen", title: "Spicy Ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3892,20 +3881,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=BeSt+Ramen", title: "BeSt Ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3928,20 +3917,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=BeSt+Spicy+Ramen", title: "BeSt Spicy Ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -3986,20 +3975,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=rats", title: "rats", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4022,20 +4011,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4058,20 +4047,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=raccoon", title: "raccoon", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4105,20 +4094,20 @@ mod tests { url: "https://www.yelp.com/search?find_desc=best+rats", title: "best rats", icon: Some( - [ - 121, - 101, - 108, - 112, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + content: [ + 121, + 101, + 108, + 112, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4261,7 +4250,6 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: None, - icon_mimetype: None, full_keyword: "amp wiki match", block_id: 0, advertiser: "Good Place Eats", @@ -4275,23 +4263,23 @@ mod tests { title: "Multimatch", url: "https://wikipedia.org/Multimatch", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "amp wiki match", }, @@ -4300,7 +4288,6 @@ mod tests { url: "https://penne.biz", raw_url: "https://penne.biz", icon: None, - icon_mimetype: None, full_keyword: "amp wiki match", block_id: 0, advertiser: "Good Place Eats", @@ -4333,7 +4320,6 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: None, - icon_mimetype: None, full_keyword: "amp wiki match", block_id: 0, advertiser: "Good Place Eats", @@ -4347,23 +4333,23 @@ mod tests { title: "Multimatch", url: "https://wikipedia.org/Multimatch", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "amp wiki match", }, @@ -4394,23 +4380,23 @@ mod tests { title: "Multimatch", url: "https://wikipedia.org/Multimatch", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "pocket wiki match", }, @@ -4717,23 +4703,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -4761,23 +4747,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -4805,23 +4791,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -4837,23 +4823,23 @@ mod tests { url: "https://www.lasagna.restaurant", raw_url: "https://www.lasagna.restaurant", icon: Some( - [ - 97, - 108, - 115, - 111, - 45, - 97, - 110, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_mimetype: Some( - "image/png", + SuggestionIcon { + content: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -5350,7 +5336,6 @@ mod tests { url: "https://www.lph-nm.biz", raw_url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los", block_id: 0, advertiser: "Los Pollos Hermanos", @@ -5559,7 +5544,6 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon: None, - icon_mimetype: None, score: 0.5, has_location_sign: false, subject_exact_match: true, diff --git a/components/suggest/src/suggest.udl b/components/suggest/src/suggest.udl index 3f6f699b823..9a2e161ca24 100644 --- a/components/suggest/src/suggest.udl +++ b/components/suggest/src/suggest.udl @@ -22,6 +22,11 @@ interface SuggestApiError { Other(string reason); }; +dictionary SuggestionIcon { + sequence content; + string mime_type; +}; + enum SuggestionProvider { "Amp", "Pocket", @@ -39,8 +44,7 @@ interface Suggestion { string title, string url, string raw_url, - sequence? icon, - string? icon_mimetype, + SuggestionIcon? icon, string full_keyword, i64 block_id, string advertiser, @@ -59,8 +63,7 @@ interface Suggestion { Wikipedia( string title, string url, - sequence? icon, - string? icon_mimetype, + SuggestionIcon? icon, string full_keyword ); Amo( @@ -76,8 +79,7 @@ interface Suggestion { Yelp( string url, string title, - sequence? icon, - string? icon_mimetype, + SuggestionIcon? icon, f64 score, boolean has_location_sign, boolean subject_exact_match, diff --git a/components/suggest/src/suggestion.rs b/components/suggest/src/suggestion.rs index 02a169df15f..c2e963e6d7b 100644 --- a/components/suggest/src/suggestion.rs +++ b/components/suggest/src/suggestion.rs @@ -16,6 +16,12 @@ const TIMESTAMP_TEMPLATE: &str = "%YYYYMMDDHH%"; /// 2 bytes shorter than [`TIMESTAMP_TEMPLATE`]. const TIMESTAMP_LENGTH: usize = 10; +#[derive(Clone, Debug, PartialEq)] +pub struct SuggestionIcon { + pub content: Vec, + pub mime_type: String, +} + /// Suggestion Types for Amp pub(crate) enum AmpSuggestionType { Mobile, @@ -28,8 +34,7 @@ pub enum Suggestion { title: String, url: String, raw_url: String, - icon: Option>, - icon_mimetype: Option, + icon: Option, full_keyword: String, block_id: i64, advertiser: String, @@ -48,8 +53,7 @@ pub enum Suggestion { Wikipedia { title: String, url: String, - icon: Option>, - icon_mimetype: Option, + icon: Option, full_keyword: String, }, Amo { @@ -65,8 +69,7 @@ pub enum Suggestion { Yelp { url: String, title: String, - icon: Option>, - icon_mimetype: Option, + icon: Option, score: f64, has_location_sign: bool, subject_exact_match: bool, diff --git a/components/suggest/src/yelp.rs b/components/suggest/src/yelp.rs index 0eb6c10d56d..97537203290 100644 --- a/components/suggest/src/yelp.rs +++ b/components/suggest/src/yelp.rs @@ -12,7 +12,7 @@ use crate::{ db::SuggestDao, provider::SuggestionProvider, rs::{DownloadedYelpSuggestion, SuggestRecordId}, - suggestion::Suggestion, + suggestion::{Suggestion, SuggestionIcon}, Result, SuggestionQuery, }; @@ -147,7 +147,7 @@ impl<'a> SuggestDao<'a> { let Some((subject, subject_exact_match)) = self.find_subject(query_string)? else { return Ok(vec![]); }; - let (icon, icon_mimetype, score) = self.fetch_custom_details()?; + let (icon, score) = self.fetch_custom_details()?; let builder = SuggestionBuilder { subject: &subject, subject_exact_match, @@ -157,7 +157,6 @@ impl<'a> SuggestDao<'a> { location: None, need_location: false, icon, - icon_mimetype, score, }; return Ok(vec![builder.into()]); @@ -189,7 +188,7 @@ impl<'a> SuggestDao<'a> { return Ok(vec![]); }; - let (icon, icon_mimetype, score) = self.fetch_custom_details()?; + let (icon, score) = self.fetch_custom_details()?; let builder = SuggestionBuilder { subject: &subject, subject_exact_match, @@ -199,7 +198,6 @@ impl<'a> SuggestDao<'a> { location, need_location, icon, - icon_mimetype, score, }; Ok(vec![builder.into()]) @@ -208,8 +206,7 @@ impl<'a> SuggestDao<'a> { /// Fetch the custom details for Yelp suggestions. /// It returns the location tuple as follows: /// ( - /// Option>: Icon data. If not found, returns None. - /// Option: Mimetype of the icon data. If not found, returns None. + /// Option: Icon data. If not found, returns None. /// f64: Reflects score field in the yelp_custom_details table. /// ) /// @@ -218,7 +215,7 @@ impl<'a> SuggestDao<'a> { /// on Remote Settings. The following query will perform a table scan against /// `yelp_custom_details` followed by an index search against `icons`, /// which should be fine since there is only one record in the first table. - fn fetch_custom_details(&self) -> Result<(Option>, Option, f64)> { + fn fetch_custom_details(&self) -> Result<(Option, f64)> { let result = self.conn.query_row_and_then_cachable( r#" SELECT @@ -242,7 +239,12 @@ impl<'a> SuggestDao<'a> { true, )?; - Ok(result) + Ok(match result { + (Some(content), Some(mime_type), score) => { + (Some(SuggestionIcon { content, mime_type }), score) + } + _ => (None, result.2), + }) } /// Find the location information from the given query string. @@ -450,8 +452,7 @@ struct SuggestionBuilder<'a> { location_sign: Option, location: Option, need_location: bool, - icon: Option>, - icon_mimetype: Option, + icon: Option, score: f64, } @@ -501,7 +502,6 @@ impl<'a> From> for Suggestion { url, title, icon: builder.icon, - icon_mimetype: builder.icon_mimetype, score: builder.score, has_location_sign: location_modifier.is_none() && builder.location_sign.is_some(), subject_exact_match: builder.subject_exact_match,