Bug 1042425 - Limit the number of search history results displayed. r=eedens
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 30 Jul 2014 14:47:01 -0700
changeset 197024 e15064c8ce6aaf07ef2f06c1cba1e5a3aa3e1272
parent 197023 eed3189b2c66db270ab8a907e050d363773d7af4
child 197025 e61d27c454a4f715419652f38b4e5faa19613f9f
push id47022
push usercbook@mozilla.com
push dateThu, 31 Jul 2014 11:07:00 +0000
treeherdermozilla-inbound@597be00ffc53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseedens
bugs1042425
milestone34.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 1042425 - Limit the number of search history results displayed. r=eedens
mobile/android/search/java/org/mozilla/search/Constants.java
mobile/android/search/java/org/mozilla/search/PreSearchFragment.java
mobile/android/search/java/org/mozilla/search/autocomplete/SearchFragment.java
--- a/mobile/android/search/java/org/mozilla/search/Constants.java
+++ b/mobile/android/search/java/org/mozilla/search/Constants.java
@@ -20,9 +20,11 @@ public class Constants {
     public static final String PRESEARCH_FRAGMENT = "org.mozilla.search.PRESEARCH_FRAGMENT";
     public static final String SEARCH_FRAGMENT = "org.mozilla.search.SEARCH_FRAGMENT";
 
     public static final String YAHOO_WEB_SEARCH_BASE_URL = "https://search.yahoo.com/search?p=";
     public static final String YAHOO_WEB_SEARCH_RESULTS_FILTER = "//search.yahoo.com";
 
     public static final String INTENT_START_SEARCH = "org.mozilla.search.intent.START_SEARCH";
     public static final String INTENT_START_SEARCH_QUERY_EXTRA = "org.mozilla.search.intent.START_SEARCH_QUERY_EXTRA";
+
+    public static final int SUGGESTION_MAX = 5;
 }
--- a/mobile/android/search/java/org/mozilla/search/PreSearchFragment.java
+++ b/mobile/android/search/java/org/mozilla/search/PreSearchFragment.java
@@ -3,43 +3,50 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.search;
 
 import android.app.Activity;
 import android.content.Intent;
 import android.database.Cursor;
 import android.graphics.Rect;
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.CursorLoader;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.SimpleCursorAdapter;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.ListView;
 
+import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserContract.SearchHistory;
 import org.mozilla.search.AcceptsSearchQuery.SuggestionAnimation;
 
 /**
  * This fragment is responsible for managing the card stream.
  */
 public class PreSearchFragment extends Fragment {
 
     private AcceptsSearchQuery searchListener;
     private SimpleCursorAdapter cursorAdapter;
 
     private ListView listView;
 
-    private final String[] PROJECTION = new String[]{SearchHistory.QUERY, SearchHistory._ID};
+    private static final String[] PROJECTION = new String[]{ SearchHistory.QUERY, SearchHistory._ID };
+
+    // Limit search history query results to 5 items. This value matches the number of search
+    // suggestions we return in SearchFragment.
+    private static final Uri SEARCH_HISTORY_URI = SearchHistory.CONTENT_URI.buildUpon().
+            appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(Constants.SUGGESTION_MAX)).build();
 
     private static final int LOADER_ID_SEARCH_HISTORY = 1;
 
     public PreSearchFragment() {
         // Mandatory empty constructor for Android's Fragment.
     }
 
     @Override
@@ -123,18 +130,18 @@ public class PreSearchFragment extends F
         super.onDestroyView();
         listView.setAdapter(null);
         listView = null;
     }
 
     private class SearchHistoryLoaderCallbacks implements LoaderManager.LoaderCallbacks<Cursor> {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            return new CursorLoader(getActivity(), SearchHistory.CONTENT_URI,
-                    PROJECTION, null, null, SearchHistory.DATE_LAST_VISITED + " DESC");
+            return new CursorLoader(getActivity(), SEARCH_HISTORY_URI, PROJECTION, null, null,
+                    SearchHistory.DATE_LAST_VISITED + " DESC");
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
             if (cursorAdapter != null) {
                 cursorAdapter.swapCursor(data);
             }
         }
--- a/mobile/android/search/java/org/mozilla/search/autocomplete/SearchFragment.java
+++ b/mobile/android/search/java/org/mozilla/search/autocomplete/SearchFragment.java
@@ -17,16 +17,17 @@ import android.text.style.ForegroundColo
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.ListView;
 
 import org.mozilla.search.AcceptsSearchQuery;
 import org.mozilla.search.AcceptsSearchQuery.SuggestionAnimation;
+import org.mozilla.search.Constants;
 import org.mozilla.search.R;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * A fragment to handle autocomplete. Its interface with the outside
  * world should be very very limited.
@@ -36,19 +37,16 @@ import java.util.List;
 public class SearchFragment extends Fragment implements AcceptsJumpTaps {
 
     private static final int LOADER_ID_SUGGESTION = 0;
     private static final String KEY_SEARCH_TERM = "search_term";
 
     // Timeout for the suggestion client to respond
     private static final int SUGGESTION_TIMEOUT = 3000;
 
-    // Maximum number of results returned by the suggestion client
-    private static final int SUGGESTION_MAX = 5;
-
     // Color of search term match in search suggestion
     private static final int SUGGESTION_HIGHLIGHT_COLOR = 0xFF999999;
 
     private AcceptsSearchQuery searchListener;
     private SuggestClient suggestClient;
     private SuggestionLoaderCallbacks suggestionLoaderCallbacks;
 
     private AutoCompleteAdapter autoCompleteAdapter;
@@ -75,19 +73,19 @@ public class SearchFragment extends Frag
         if (activity instanceof AcceptsSearchQuery) {
             searchListener = (AcceptsSearchQuery) activity;
         } else {
             throw new ClassCastException(activity.toString() + " must implement AcceptsSearchQuery.");
         }
 
         // TODO: Don't hard-code this template string (bug 1039758)
         final String template = "https://search.yahoo.com/sugg/ff?" +
-                "output=fxjson&appid=ffm&command=__searchTerms__&nresults=" + SUGGESTION_MAX;
+                "output=fxjson&appid=ffm&command=__searchTerms__&nresults=" + Constants.SUGGESTION_MAX;
 
-        suggestClient = new SuggestClient(activity, template, SUGGESTION_TIMEOUT, SUGGESTION_MAX);
+        suggestClient = new SuggestClient(activity, template, SUGGESTION_TIMEOUT, Constants.SUGGESTION_MAX);
         suggestionLoaderCallbacks = new SuggestionLoaderCallbacks();
 
         autoCompleteAdapter = new AutoCompleteAdapter(activity, this);
     }
 
     @Override
     public void onDetach() {
         super.onDetach();