@@ -17,14 +17,13 @@ use sql_support::{open_database, repeat_sql_vars, ConnExt};
1717use crate :: {
1818 config:: { SuggestGlobalConfig , SuggestProviderConfig } ,
1919 error:: RusqliteResultExt ,
20- fakespot,
2120 geoname:: GeonameCache ,
2221 provider:: { AmpMatchingStrategy , SuggestionProvider } ,
2322 query:: { full_keywords_to_fts_content, FtsQuery } ,
2423 rs:: {
2524 DownloadedAmoSuggestion , DownloadedAmpSuggestion , DownloadedDynamicRecord ,
26- DownloadedDynamicSuggestion , DownloadedFakespotSuggestion , DownloadedMdnSuggestion ,
27- DownloadedWikipediaSuggestion , Record , SuggestRecordId , SuggestRecordType ,
25+ DownloadedDynamicSuggestion , DownloadedMdnSuggestion , DownloadedWikipediaSuggestion ,
26+ Record , SuggestRecordId , SuggestRecordType ,
2827 } ,
2928 schema:: { clear_database, SuggestConnectionInitializer } ,
3029 suggestion:: { cook_raw_suggestion_url, FtsMatchInfo , Suggestion } ,
@@ -762,113 +761,6 @@ impl<'a> SuggestDao<'a> {
762761 Ok ( suggestions)
763762 }
764763
765- /// Fetches Fakespot suggestions
766- pub fn fetch_fakespot_suggestions ( & self , query : & SuggestionQuery ) -> Result < Vec < Suggestion > > {
767- let fts_query = query. fts_query ( ) ;
768- let sql = r#"
769- SELECT
770- s.id,
771- s.title,
772- s.url,
773- s.score,
774- f.fakespot_grade,
775- f.product_id,
776- f.rating,
777- f.total_reviews,
778- i.data,
779- i.mimetype,
780- f.keywords,
781- f.product_type
782- FROM
783- suggestions s
784- JOIN
785- fakespot_fts fts
786- ON fts.rowid = s.id
787- JOIN
788- fakespot_custom_details f
789- ON f.suggestion_id = s.id
790- LEFT JOIN
791- icons i
792- ON i.id = f.icon_id
793- WHERE
794- fakespot_fts MATCH ?
795- ORDER BY
796- s.score DESC
797- "#
798- . to_string ( ) ;
799-
800- // Store the list of results plus the suggestion id for calculating the FTS match info
801- let mut results =
802- self . conn
803- . query_rows_and_then_cached ( & sql, ( & fts_query. match_arg , ) , |row| {
804- let id: usize = row. get ( 0 ) ?;
805- let score = fakespot:: FakespotScore :: new (
806- & query. keyword ,
807- row. get ( 10 ) ?,
808- row. get ( 11 ) ?,
809- row. get ( 3 ) ?,
810- )
811- . as_suggest_score ( ) ;
812- Result :: Ok ( (
813- Suggestion :: Fakespot {
814- title : row. get ( 1 ) ?,
815- url : row. get ( 2 ) ?,
816- score,
817- fakespot_grade : row. get ( 4 ) ?,
818- product_id : row. get ( 5 ) ?,
819- rating : row. get ( 6 ) ?,
820- total_reviews : row. get ( 7 ) ?,
821- icon : row. get ( 8 ) ?,
822- icon_mimetype : row. get ( 9 ) ?,
823- match_info : None ,
824- } ,
825- id,
826- ) )
827- } ) ?;
828- // Sort the results, then add the FTS match info to the first one
829- // For performance reasons, this is only calculated for the result with the highest score.
830- // We assume that only one that will be shown to the user and therefore the only one we'll
831- // collect metrics for.
832- results. sort ( ) ;
833- if let Some ( ( suggestion, id) ) = results. first_mut ( ) {
834- match suggestion {
835- Suggestion :: Fakespot {
836- match_info, title, ..
837- } => {
838- * match_info = Some ( self . fetch_fakespot_fts_match_info ( & fts_query, * id, title) ?) ;
839- }
840- _ => unreachable ! ( ) ,
841- }
842- }
843- Ok ( results
844- . into_iter ( )
845- . map ( |( suggestion, _) | suggestion)
846- . collect ( ) )
847- }
848-
849- fn fetch_fakespot_fts_match_info (
850- & self ,
851- fts_query : & FtsQuery < ' _ > ,
852- suggestion_id : usize ,
853- title : & str ,
854- ) -> Result < FtsMatchInfo > {
855- let prefix = if fts_query. is_prefix_query {
856- // If the query was a prefix match query then test if the query without the prefix
857- // match would have also matched. If not, then this counts as a prefix match.
858- let sql = "SELECT 1 FROM fakespot_fts WHERE rowid = ? AND fakespot_fts MATCH ?" ;
859- let params = ( & suggestion_id, & fts_query. match_arg_without_prefix_match ) ;
860- !self . conn . exists ( sql, params) ?
861- } else {
862- // If not, then it definitely wasn't a prefix match
863- false
864- } ;
865-
866- Ok ( FtsMatchInfo {
867- prefix,
868- stemming : fts_query. match_required_stemming ( title) ,
869- } )
870- }
871-
872764 /// Fetches dynamic suggestions
873765 pub fn fetch_dynamic_suggestions ( & self , query : & SuggestionQuery ) -> Result < Vec < Suggestion > > {
874766 let Some ( suggestion_types) = query
@@ -1114,27 +1006,6 @@ impl<'a> SuggestDao<'a> {
11141006 Ok ( ( ) )
11151007 }
11161008
1117- /// Inserts all suggestions from a downloaded Fakespot attachment into the database.
1118- pub fn insert_fakespot_suggestions (
1119- & mut self ,
1120- record_id : & SuggestRecordId ,
1121- suggestions : & [ DownloadedFakespotSuggestion ] ,
1122- ) -> Result < ( ) > {
1123- let mut suggestion_insert = SuggestionInsertStatement :: new ( self . conn ) ?;
1124- let mut fakespot_insert = FakespotInsertStatement :: new ( self . conn ) ?;
1125- for suggestion in suggestions {
1126- let suggestion_id = suggestion_insert. execute (
1127- record_id,
1128- & suggestion. title ,
1129- & suggestion. url ,
1130- suggestion. score ,
1131- SuggestionProvider :: Fakespot ,
1132- ) ?;
1133- fakespot_insert. execute ( suggestion_id, suggestion) ?;
1134- }
1135- Ok ( ( ) )
1136- }
1137-
11381009 /// Inserts dynamic suggestion records data into the database.
11391010 pub fn insert_dynamic_suggestions (
11401011 & mut self ,
@@ -1295,14 +1166,6 @@ impl<'a> SuggestDao<'a> {
12951166 named_params ! { ":record_id" : record_id. as_str( ) } ,
12961167 ) ?;
12971168 self . scope . err_if_interrupted ( ) ?;
1298- self . conn . execute_cached (
1299- "
1300- DELETE FROM fakespot_fts
1301- WHERE rowid IN (SELECT id from suggestions WHERE record_id = :record_id)
1302- " ,
1303- named_params ! { ":record_id" : record_id. as_str( ) } ,
1304- ) ?;
1305- self . scope . err_if_interrupted ( ) ?;
13061169 self . conn . execute_cached (
13071170 "DELETE FROM suggestions WHERE record_id = :record_id" ,
13081171 named_params ! { ":record_id" : record_id. as_str( ) } ,
@@ -1677,51 +1540,6 @@ impl<'conn> MdnInsertStatement<'conn> {
16771540 }
16781541}
16791542
1680- struct FakespotInsertStatement < ' conn > ( rusqlite:: Statement < ' conn > ) ;
1681-
1682- impl < ' conn > FakespotInsertStatement < ' conn > {
1683- fn new ( conn : & ' conn Connection ) -> Result < Self > {
1684- Ok ( Self ( conn. prepare (
1685- "INSERT INTO fakespot_custom_details(
1686- suggestion_id,
1687- fakespot_grade,
1688- product_id,
1689- keywords,
1690- product_type,
1691- rating,
1692- total_reviews,
1693- icon_id
1694- )
1695- VALUES(?, ?, ?, ?, ?, ?, ?, ?)
1696- " ,
1697- ) ?) )
1698- }
1699-
1700- fn execute (
1701- & mut self ,
1702- suggestion_id : i64 ,
1703- fakespot : & DownloadedFakespotSuggestion ,
1704- ) -> Result < ( ) > {
1705- let icon_id = fakespot
1706- . product_id
1707- . split_once ( '-' )
1708- . map ( |( vendor, _) | format ! ( "fakespot-{vendor}" ) ) ;
1709- self . 0
1710- . execute ( (
1711- suggestion_id,
1712- & fakespot. fakespot_grade ,
1713- & fakespot. product_id ,
1714- & fakespot. keywords . to_lowercase ( ) ,
1715- & fakespot. product_type . to_lowercase ( ) ,
1716- fakespot. rating ,
1717- fakespot. total_reviews ,
1718- icon_id,
1719- ) )
1720- . with_context ( "fakespot insert" ) ?;
1721- Ok ( ( ) )
1722- }
1723- }
1724-
17251543struct DynamicInsertStatement < ' conn > ( rusqlite:: Statement < ' conn > ) ;
17261544
17271545impl < ' conn > DynamicInsertStatement < ' conn > {
0 commit comments