Bug 1330973 - Use website description length for highlights ranking. r=Grisha
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 02 Feb 2017 17:08:30 +0100
changeset 374887 93af928758e78c567610e7d68ac2ff4f6fb8480b
parent 374886 c7220d8cf144119bac43d78c6953e50c54995abb
child 374888 32604a6dd45e988b485b3f93b2a5dc5410a89b1c
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha
bugs1330973
milestone54.0a1
Bug 1330973 - Use website description length for highlights ranking. r=Grisha MozReview-Commit-ID: 7kZjNb2MSJ7
mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightCandidate.java
mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightsRanking.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/model/Metadata.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightCandidate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightCandidate.java
@@ -113,20 +113,19 @@ import static org.mozilla.gecko.activity
                     FEATURE_BOOKMARK_AGE_IN_MILLISECONDS,
                     0d);
         } else {
             candidate.features.put(
                     FEATURE_BOOKMARK_AGE_IN_MILLISECONDS,
                     Math.max(1, System.currentTimeMillis() - cursor.getDouble(bookmarkDateColumnIndex)));
         }
 
-        // TODO: We do not know the description length yet. Let's assume it's 0 for now. (Bug 1330973)
         candidate.features.put(
                 FEATURE_DESCRIPTION_LENGTH,
-                0d);
+                (double) candidate.highlight.getMetadata().getDescriptionLength());
 
         final Uri uri = Uri.parse(candidate.highlight.getUrl());
 
         candidate.host = uri.getHost();
 
         candidate.features.put(
                 FEATURE_PATH_LENGTH,
                 (double) uri.getPathSegments().size());
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightsRanking.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ranking/HighlightsRanking.java
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.activitystream.ranking;
 
 import android.database.Cursor;
 import android.support.annotation.VisibleForTesting;
+import android.util.Log;
 
 import org.mozilla.gecko.home.activitystream.model.Highlight;
 
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/model/Metadata.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/model/Metadata.java
@@ -18,29 +18,31 @@ public class Metadata {
 
     public static Metadata fromCursor(Cursor cursor) {
         return new Metadata(
                 cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.METADATA)));
     }
 
     private String provider;
     private String imageUrl;
+    private int descriptionLength;
 
     private Metadata(String json) {
         if (TextUtils.isEmpty(json)) {
             // Just use default values. It's better to have an empty Metadata object instead of
             // juggling with null values.
             return;
         }
 
         try {
             JSONObject object = new JSONObject(json);
 
             provider = object.optString("provider");
             imageUrl = object.optString("image_url");
+            descriptionLength = object.optInt("description_length");
         } catch (JSONException e) {
             Log.w(LOGTAG, "JSONException while parsing metadata", e);
         }
     }
 
     public boolean hasProvider() {
         return !TextUtils.isEmpty(provider);
     }
@@ -55,9 +57,13 @@ public class Metadata {
 
     public boolean hasImageUrl() {
         return imageUrl != null;
     }
 
     public String getProvider() {
         return provider;
     }
+
+    public int getDescriptionLength() {
+        return descriptionLength;
+    }
 }