From 5fb03e6606e6f5bdbb56e6143a647cf2acd282be Mon Sep 17 00:00:00 2001 From: dadaa Date: Thu, 16 May 2024 23:50:26 +0900 Subject: [PATCH] Introduce suggestion icon struct --- components/suggest/src/db.rs | 30 +- components/suggest/src/lib.rs | 2 +- components/suggest/src/store.rs | 3315 +++++++++++++------------- components/suggest/src/suggest.udl | 17 +- components/suggest/src/suggestion.rs | 18 +- components/suggest/src/yelp.rs | 64 +- 6 files changed, 1707 insertions(+), 1739 deletions(-) diff --git a/components/suggest/src/db.rs b/components/suggest/src/db.rs index 1597f4f4f2d..1103676de78 100644 --- a/components/suggest/src/db.rs +++ b/components/suggest/src/db.rs @@ -26,7 +26,7 @@ use crate::{ DownloadedWikipediaSuggestion, SuggestRecordId, }, schema::{clear_database, SuggestConnectionInitializer}, - suggestion::{cook_raw_suggestion_url, AmpSuggestionType, Suggestion}, + suggestion::{cook_raw_suggestion_url, AmpSuggestionType, Suggestion, SuggestionIcon}, Result, SuggestionQuery, }; @@ -274,7 +274,7 @@ impl<'a> SuggestDao<'a> { amp.iab_category, amp.impression_url, amp.click_url, - i.data AS icon, + i.data AS icon_data, i.mimetype AS icon_mimetype FROM amp_custom_details amp @@ -290,6 +290,12 @@ 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_data = row.get::<_, Option<_>>("icon_data")?; + let icon_mime_type = row.get::<_, Option<_>>("icon_mimetype")?; + let icon = icon_data.map(|data| SuggestionIcon { + data, + mime_type: icon_mime_type.unwrap_or_default(), + }); Ok(Suggestion::Amp { block_id: row.get("block_id")?, @@ -300,8 +306,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, @@ -353,7 +358,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 @@ -365,21 +370,20 @@ impl<'a> SuggestDao<'a> { ":suggestion_id": suggestion_id }, |row| -> Result<_> { - Ok(( - row.get::<_, Option>>(0)?, - row.get::<_, Option>(1)?, - )) + Ok(Some(SuggestionIcon { + data: 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, }) }, )?; @@ -961,7 +965,7 @@ impl<'a> SuggestDao<'a> { } /// Inserts or replaces an icon for a suggestion into the database. - pub fn put_icon(&mut self, icon_id: &str, data: &[u8], mimetype: &str) -> Result<()> { + pub fn put_icon(&mut self, icon_id: &str, data: &[u8], mime_type: &str) -> Result<()> { self.conn.execute( "INSERT OR REPLACE INTO icons( id, @@ -976,7 +980,7 @@ impl<'a> SuggestDao<'a> { named_params! { ":id": icon_id, ":data": data, - ":mimetype": mimetype, + ":mimetype": mime_type, }, )?; Ok(()) diff --git a/components/suggest/src/lib.rs b/components/suggest/src/lib.rs index 93b456b8b49..ef78e48f505 100644 --- a/components/suggest/src/lib.rs +++ b/components/suggest/src/lib.rs @@ -22,7 +22,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 276633c871b..2e5cdfaa8d4 100644 --- a/components/suggest/src/store.rs +++ b/components/suggest/src/store.rs @@ -857,7 +857,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", @@ -934,7 +933,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", @@ -1095,23 +1093,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 { + data: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -1136,23 +1134,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 { + data: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "penne", block_id: 0, @@ -1317,7 +1315,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", @@ -1332,7 +1329,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", @@ -1357,7 +1353,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", @@ -1372,7 +1367,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", @@ -1396,7 +1390,6 @@ mod tests { title: "Los Pollos Hermanos - Albuquerque - Wiki", url: "https://www.lph-nm.biz", icon: None, - icon_mimetype: None, full_keyword: "los", }, ] @@ -1414,7 +1407,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", @@ -1484,7 +1476,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", @@ -1573,7 +1564,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", @@ -1659,7 +1649,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", @@ -1683,7 +1672,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", @@ -1834,27 +1822,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 { + data: [ + 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, @@ -1879,26 +1867,27 @@ 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 { + data: [ + 110, + 101, + 119, + 45, + 108, + 97, + 115, + 97, + 103, + 110, + 97, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "los", block_id: 0, @@ -2686,23 +2675,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 { + data: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -2752,23 +2741,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "multimatch", }, @@ -2811,23 +2800,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "multimatch", }, @@ -2883,23 +2872,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 { + data: [ + 105, + 45, + 97, + 109, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -2967,23 +2956,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -2991,23 +2980,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -3027,23 +3016,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "california", }, @@ -3244,59 +3233,59 @@ 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_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3319,59 +3308,59 @@ 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_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3394,59 +3383,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=best+ramen+delivery&find_loc=tokyo", title: "best ramen delivery in tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3491,59 +3480,59 @@ 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_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3577,59 +3566,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+delivery&find_loc=tokyo", title: "ramen delivery in tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3652,59 +3641,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+super+delivery&find_loc=tokyo", title: "ramen super delivery in tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3738,59 +3727,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen in tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3813,59 +3802,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen near tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3899,59 +3888,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=San+Francisco", title: "ramen in San Francisco", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -3974,59 +3963,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen in", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -4049,59 +4038,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+near+by", title: "ramen near by", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4124,59 +4113,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen+near+me", title: "ramen near me", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4210,59 +4199,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4285,59 +4274,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", title: "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4404,59 +4393,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4479,59 +4468,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4546,67 +4535,67 @@ mod tests { SuggestionQuery { keyword: "ramen in tokyo yelp".into(), providers: vec![SuggestionProvider::Yelp], - limit: None, - }, - expect![[r#" - [ - Yelp { - url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", - title: "ramen in tokyo", - icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", - ), - icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], + limit: None, + }, + expect![[r#" + [ + Yelp { + url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", + title: "ramen in tokyo", + icon_light_theme: Some( + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + icon_dark_theme: Some( + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -4629,59 +4618,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo", title: "ramen in tokyo", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: true, @@ -4704,59 +4693,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4790,59 +4779,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=Spicy+Ramen", title: "Spicy Ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4865,59 +4854,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=BeSt+Ramen", title: "BeSt Ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -4940,59 +4929,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=BeSt+Spicy+Ramen", title: "BeSt Spicy Ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -5037,59 +5026,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=rats", title: "rats", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -5112,59 +5101,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -5187,59 +5176,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=raccoon", title: "raccoon", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -5273,59 +5262,59 @@ mod tests { url: "https://www.yelp.com/search?find_desc=best+rats", title: "best rats", icon_light_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 108, - 105, - 103, - 104, - 116, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_light_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 108, + 105, + 103, + 104, + 116, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), icon_dark_theme: Some( - [ - 121, - 101, - 108, - 112, - 45, - 100, - 97, - 114, - 107, - 45, - 116, - 104, - 101, - 109, - 101, - 45, - 105, - 99, - 111, - 110, - ], - ), - icon_dark_theme_mimetype: Some( - "image/svg+xml", + SuggestionIcon { + data: [ + 121, + 101, + 108, + 112, + 45, + 100, + 97, + 114, + 107, + 45, + 116, + 104, + 101, + 109, + 101, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/svg+xml", + }, ), score: 0.5, has_location_sign: false, @@ -5468,7 +5457,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", @@ -5482,23 +5470,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "amp wiki match", }, @@ -5507,7 +5495,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", @@ -5540,7 +5527,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", @@ -5554,23 +5540,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "amp wiki match", }, @@ -5601,23 +5587,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "pocket wiki match", }, @@ -5924,23 +5910,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -5968,23 +5954,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -6012,23 +5998,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -6044,23 +6030,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 { + data: [ + 97, + 108, + 115, + 111, + 45, + 97, + 110, + 45, + 105, + 99, + 111, + 110, + ], + mime_type: "image/png", + }, ), full_keyword: "lasagna", block_id: 0, @@ -6304,7 +6290,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", @@ -6507,9 +6492,7 @@ mod tests { url: "https://www.yelp.com/search?find_desc=ramen", title: "ramen", icon_light_theme: None, - icon_light_theme_mimetype: None, icon_dark_theme: None, - icon_dark_theme_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 52b8b5e6546..ece3ffbcd26 100644 --- a/components/suggest/src/suggest.udl +++ b/components/suggest/src/suggest.udl @@ -25,6 +25,11 @@ interface SuggestApiError { Other(string reason); }; +dictionary SuggestionIcon { + sequence data; + string mime_type; +}; + enum SuggestionProvider { "Amp", "Pocket", @@ -42,8 +47,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, @@ -62,8 +66,7 @@ interface Suggestion { Wikipedia( string title, string url, - sequence? icon, - string? icon_mimetype, + SuggestionIcon? icon, string full_keyword ); Amo( @@ -79,10 +82,8 @@ interface Suggestion { Yelp( string url, string title, - sequence? icon_light_theme, - string? icon_light_theme_mimetype, - sequence? icon_dark_theme, - string? icon_dark_theme_mimetype, + SuggestionIcon? icon_light_theme, + SuggestionIcon? icon_dark_theme, 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 548457675cf..0f885d7669f 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 data: 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,10 +69,8 @@ pub enum Suggestion { Yelp { url: String, title: String, - icon_light_theme: Option>, - icon_light_theme_mimetype: Option, - icon_dark_theme: Option>, - icon_dark_theme_mimetype: Option, + icon_light_theme: Option, + icon_dark_theme: 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 c215882de33..9f70ff64fa2 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, }; @@ -148,13 +148,7 @@ impl<'a> SuggestDao<'a> { let Some((subject, subject_exact_match)) = self.find_subject(query_string)? else { return Ok(vec![]); }; - let ( - icon_light_theme, - icon_light_theme_mimetype, - icon_dark_theme, - icon_dark_theme_mimetype, - score, - ) = self.fetch_custom_details()?; + let (icon_light_theme, icon_dark_theme, score) = self.fetch_custom_details()?; let builder = SuggestionBuilder { subject: &subject, subject_exact_match, @@ -164,9 +158,7 @@ impl<'a> SuggestDao<'a> { location: None, need_location: false, icon_light_theme, - icon_light_theme_mimetype, icon_dark_theme, - icon_dark_theme_mimetype, score, }; return Ok(vec![builder.into()]); @@ -198,13 +190,7 @@ impl<'a> SuggestDao<'a> { return Ok(vec![]); }; - let ( - icon_light_theme, - icon_light_theme_mimetype, - icon_dark_theme, - icon_dark_theme_mimetype, - score, - ) = self.fetch_custom_details()?; + let (icon_light_theme, icon_dark_theme, score) = self.fetch_custom_details()?; let builder = SuggestionBuilder { subject: &subject, subject_exact_match, @@ -214,9 +200,7 @@ impl<'a> SuggestDao<'a> { location, need_location, icon_light_theme, - icon_light_theme_mimetype, icon_dark_theme, - icon_dark_theme_mimetype, score, }; Ok(vec![builder.into()]) @@ -225,10 +209,8 @@ impl<'a> SuggestDao<'a> { /// Fetch the custom details for Yelp suggestions. /// It returns the location tuple as follows: /// ( - /// Option>: Icon data for light theme. If not found, returns None. - /// Option: Mimetype of the icon data for light theme. If not found, returns None. - /// Option>: Icon data for dark theme. If not found, returns None. - /// Option: Mimetype of the icon data for dark theme. If not found, returns None. + /// Option: Icon for light theme. If not found, returns None. + /// Option: Icon for dark theme. If not found, returns None. /// f64: Reflects score field in the yelp_custom_details table. /// ) /// @@ -239,13 +221,7 @@ impl<'a> SuggestDao<'a> { /// which should be fine since there is only one record in the first table. fn fetch_custom_details( &self, - ) -> Result<( - Option>, - Option, - Option>, - Option, - f64, - )> { + ) -> Result<(Option, Option, f64)> { let result = self.conn.query_row_and_then_cachable( r#" SELECT @@ -263,13 +239,19 @@ impl<'a> SuggestDao<'a> { "#, (), |row| -> Result<_> { - Ok(( - row.get::<_, Option>>(0)?, - row.get::<_, Option>(1)?, - row.get::<_, Option>>(2)?, - row.get::<_, Option>(3)?, - row.get::<_, f64>(4)?, - )) + let icon_data_light_theme = row.get::<_, Option>>(0)?; + let icon_mime_type_light_theme = row.get::<_, Option>(1)?; + let icon_light_theme = icon_data_light_theme.map(|data| SuggestionIcon { + data, + mime_type: icon_mime_type_light_theme.unwrap_or_default(), + }); + let icon_data_dark_theme = row.get::<_, Option>>(2)?; + let icon_mime_type_dark_theme = row.get::<_, Option>(3)?; + let icon_dark_theme = icon_data_dark_theme.map(|data| SuggestionIcon { + data, + mime_type: icon_mime_type_dark_theme.unwrap_or_default(), + }); + Ok((icon_light_theme, icon_dark_theme, row.get::<_, f64>(4)?)) }, true, )?; @@ -482,10 +464,8 @@ struct SuggestionBuilder<'a> { location_sign: Option, location: Option, need_location: bool, - icon_light_theme: Option>, - icon_light_theme_mimetype: Option, - icon_dark_theme: Option>, - icon_dark_theme_mimetype: Option, + icon_light_theme: Option, + icon_dark_theme: Option, score: f64, } @@ -535,9 +515,7 @@ impl<'a> From> for Suggestion { url, title, icon_light_theme: builder.icon_light_theme, - icon_light_theme_mimetype: builder.icon_light_theme_mimetype, icon_dark_theme: builder.icon_dark_theme, - icon_dark_theme_mimetype: builder.icon_dark_theme_mimetype, score: builder.score, has_location_sign: location_modifier.is_none() && builder.location_sign.is_some(), subject_exact_match: builder.subject_exact_match,