/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/// Fakespot-specific logic /// /// Score used to order Fakespot suggestions /// /// FakespotScore contains several components, each in the range of [0, 1] pubstruct FakespotScore { /// Did the query match the `keywords` field exactly?
keywords_score: f64, /// How well did the query match the `product_type` field?
product_type_score: f64, /// Fakespot score from the RS data, this reflects the average review, number of reviews, /// Fakespot grade, etc.
fakespot_score: f64,
}
/// Convert a FakespotScore into the value to use in `Sugggestion::Fakespot::score` /// /// This converts FakespotScore into a single float that: /// - Is > 0.3 so that Fakespot suggestions are preferred to AMP ones /// - Reflects the Fakespot ordering: /// - Suggestions with higher keywords_score are greater /// - If keywords_score is tied, then suggestions with higher product_type_scores are greater /// - If both are tied, then suggestions with higher fakespot_score are greater pubfn as_suggest_score(&self) -> f64 { 0.30 + (0.01 * self.keywords_score)
+ (0.001 * self.product_type_score)
+ (0.0001 * self.fakespot_score)
}
}
/// Split a string containing terms into a list of individual terms, normalized to lowercase fn split_terms(string: &str) -> Vec<&str> {
string.split_whitespace().collect()
}
fn calc_keywords_score(query_terms: &[&str], keywords: &str) -> f64 { // Note: We can assume keywords is lower-case, since we do that during ingestion let keyword_terms = split_terms(keywords); if keyword_terms.is_empty() { return0.0;
}
fn calc_product_type_score(query_terms: &[&str], product_type: &str) -> f64 { // Note: We can assume product_type is lower-case, since we do that during ingestion let product_type_terms = split_terms(product_type); if product_type_terms.is_empty() { return0.0;
} let count = product_type_terms
.iter()
.filter(|t| query_terms.contains(t))
.count() as f64;
count / product_type_terms.len() as f64
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.