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 394837 93af928758e78c567610e7d68ac2ff4f6fb8480b
parent 394836 c7220d8cf144119bac43d78c6953e50c54995abb
child 394838 32604a6dd45e988b485b3f93b2a5dc5410a89b1c
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha
bugs1330973
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
+    }
 }