Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Bug 1042425 - Limit the number of search history results displayed. r…
Browse files Browse the repository at this point in the history
…=eedens
  • Loading branch information
leibovic committed Jul 30, 2014
1 parent 5c2bcb5 commit f1beb11
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/search/Constants.java
Expand Up @@ -25,4 +25,6 @@ public class Constants {

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;
}
13 changes: 10 additions & 3 deletions app/src/main/java/org/mozilla/search/PreSearchFragment.java
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -21,6 +22,7 @@
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;

Expand All @@ -34,7 +36,12 @@ public class PreSearchFragment extends Fragment {

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;

Expand Down Expand Up @@ -128,8 +135,8 @@ public void onDestroyView() {
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
Expand Down
Expand Up @@ -22,6 +22,7 @@

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;
Expand All @@ -41,9 +42,6 @@ public class SearchFragment extends Fragment implements AcceptsJumpTaps {
// 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;

Expand Down Expand Up @@ -80,9 +78,9 @@ public void onAttach(Activity activity) {

// 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);
Expand Down

0 comments on commit f1beb11

Please sign in to comment.