jenkins-bot has submitted this change and it was merged.
Change subject: Refine search logic a bit.
......................................................................
Refine search logic a bit.
- No longer offer the choice of Title vs. Full-text search.
- Default to Title search, but if it returns fewer than 5 results, then
switch to Full-text search seamlessly.
- Switch back to Title search when a new search term is given.
- Once we're convinced that this method is better than before, we can
refactor the whole thing so that there's only one sub-fragment (instead
of Title vs. Full).
Change-Id: Ibf9ebc49299393a0afc17b87b4b8bc02f0ba74a6
---
M wikipedia/res/layout/fragment_search.xml
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/search/RecentSearchesFragment.java
M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
M wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
6 files changed, 32 insertions(+), 102 deletions(-)
Approvals:
BearND: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia/res/layout/fragment_search.xml
b/wikipedia/res/layout/fragment_search.xml
index c18f7eb..248c5f4 100644
--- a/wikipedia/res/layout/fragment_search.xml
+++ b/wikipedia/res/layout/fragment_search.xml
@@ -15,35 +15,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
- <LinearLayout
- android:id="@+id/search_type_button_container"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal">
- <Button
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:layout_weight="0.5"
- android:id="@+id/button_search_title"
- android:background="?attr/window_background_color"
- android:textColor="?attr/edit_text_color"
- android:text="@string/search_titles_button"
- />
-
- <View android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="?attr/list_separator_color" />
-
- <Button
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:layout_weight="0.5"
- android:id="@+id/button_search_full"
- android:background="?attr/window_background_color"
- android:textColor="?attr/edit_text_color"
- android:text="@string/search_full_button"
- />
- </LinearLayout>
-
<View android:layout_width="match_parent"
android:layout_height="0.5dp" android:background="?attr/list_separator_color" />
<FrameLayout
diff --git a/wikipedia/res/values-qq/strings.xml
b/wikipedia/res/values-qq/strings.xml
index 9a71b89..74e6467 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -341,9 +341,6 @@
<string name="search_recent_header">Label at the top of the list of recent
searches that the user performed.</string>
<string name="button_clear_all_recent_searches">Button hint for clearing
search history; visible when in search mode.</string>
<string name="clear_recent_searches_confirm">Dialog message that asks if the
user really wants to clear the search history.</string>
- <string name="search_titles_button">Button label for searching page title
matches.
-{{Identical|Title}}</string>
- <string name="search_full_button">Button label for searching the full text
of pages.</string>
<string name="toc_hint">Instructions how to open the Table of Contents
drawer. In left-to-right languages (most) this means to swipe left from the
right edge. In right-to-left languages (Hebrew, Arabic, etc.) this means to
swipe right from the left edge. \'\'\'In RTL languages\'\'\' please adjust the
text to say right swipe instead of left swipe.</string>
<string name="toc_know_it">Button text to acknowledge instructions for
opening Table of Contents drawer.</string>
<string name="error_browser_not_found">Toast message shown when we try to
open an external browser but none seems to be installed.</string>
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 5318efa..e46c06e 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -252,8 +252,6 @@
<string name="search_recent_header">Recent searches:</string>
<string name="button_clear_all_recent_searches">Clear recent
searches</string>
<string name="clear_recent_searches_confirm">Are you sure you want to
clear your search history?</string>
- <string name="search_titles_button">Titles</string>
- <string name="search_full_button">Within articles</string>
<string name="toc_hint">Swipe left for sections, or use the menu button on
the top right.</string>
<string name="toc_know_it">Got it</string>
<string name="error_browser_not_found">Could not open web page (no browser
app found).</string>
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/RecentSearchesFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/RecentSearchesFragment.java
index ebddd08..ced4730 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/RecentSearchesFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/RecentSearchesFragment.java
@@ -60,7 +60,7 @@
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
RecentSearch entry = (RecentSearch) view.getTag();
- searchFragment.switchToTitleSearch(entry.getText());
+ searchFragment.switchToSearch(entry.getText());
}
});
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
index e695983..f3874c9 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
@@ -13,7 +13,6 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
-import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SearchView;
@@ -24,7 +23,6 @@
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
-import android.widget.TextView;
public class SearchArticlesFragment extends Fragment {
private static final String ARG_LAST_SEARCHED_TEXT = "lastSearchedText";
@@ -53,14 +51,6 @@
private String lastSearchedText;
/**
- * Whether the last search was forced. A search is forced if the user
explicitly
- * clicks on the buttons to select Title or Full search. It's also forced
if the user
- * is taken to Full search when a Title search produced no results.
- * A search is NOT forced when it comes from the user typing characters in
the search field.
- */
- private boolean lastSearchForced = false;
-
- /**
* View that contains the whole Search fragment. This is what should be
shown/hidden when
* the search is called for from the main activity.
*/
@@ -81,9 +71,6 @@
private RecentSearchesFragment recentSearchesFragment;
private TitleSearchFragment titleSearchFragment;
private FullSearchFragment fullSearchFragment;
-
- private View buttonTitleSearch;
- private View buttonFullSearch;
public SearchArticlesFragment() {
}
@@ -137,37 +124,13 @@
recentSearchesFragment =
(RecentSearchesFragment)getChildFragmentManager().findFragmentById(R.id.search_panel_recent);
searchTypesContainer =
parentLayout.findViewById(R.id.search_panel_types);
- buttonTitleSearch =
parentLayout.findViewById(R.id.button_search_title);
- buttonTitleSearch.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (getActivePanel() == PANEL_TITLE_SEARCH) {
- return;
- }
- showPanel(PANEL_TITLE_SEARCH);
- startSearch(lastSearchedText, true);
- }
- });
-
- buttonFullSearch = parentLayout.findViewById(R.id.button_search_full);
- buttonFullSearch.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (getActivePanel() == PANEL_FULL_SEARCH) {
- return;
- }
- showPanel(PANEL_FULL_SEARCH);
- startSearch(lastSearchedText, true);
- }
- });
-
titleSearchFragment =
(TitleSearchFragment)getChildFragmentManager().findFragmentById(R.id.fragment_search_title);
- titleSearchFragment.setOnNoResultsListener(new
TitleSearchFragment.OnNoResultsListener() {
+ titleSearchFragment.setOnResultsCountListener(new
TitleSearchFragment.OnResultsCountListener() {
@Override
- public void onNoResults() {
- if (lastSearchForced) {
- // don't automatically go to Full search if the previous
search was forced.
- // i.e. if the user had explicitly clicked on Title search.
+ public void onResultsCount(int count) {
+ final int minTitleResults = 5;
+ if (count >= minTitleResults) {
+ // got enough title results, so don't switch over to full
text.
return;
}
if (fullSearchDisabled) {
@@ -206,11 +169,7 @@
outState.putInt(ARG_SEARCH_CURRENT_PANEL, getActivePanel());
}
- public void switchToTitleSearch(String queryText) {
- if (getActivePanel() == PANEL_TITLE_SEARCH) {
- return;
- }
- showPanel(PANEL_TITLE_SEARCH);
+ public void switchToSearch(String queryText) {
startSearch(queryText, true);
searchView.setQuery(queryText, false);
}
@@ -243,18 +202,10 @@
break;
case PANEL_TITLE_SEARCH:
searchTypesContainer.setVisibility(View.VISIBLE);
-
buttonTitleSearch.setBackgroundColor(getResources().getColor(Utils.getThemedAttributeId(getActivity(),
R.attr.search_background_color)));
- ((TextView)buttonTitleSearch).setTypeface(null, Typeface.BOLD);
-
buttonFullSearch.setBackgroundColor(getResources().getColor(Utils.getThemedAttributeId(getActivity(),
R.attr.window_background_color)));
- ((TextView)buttonFullSearch).setTypeface(null,
Typeface.NORMAL);
titleSearchFragment.show();
break;
case PANEL_FULL_SEARCH:
searchTypesContainer.setVisibility(View.VISIBLE);
-
buttonFullSearch.setBackgroundColor(getResources().getColor(Utils.getThemedAttributeId(getActivity(),
R.attr.search_background_color)));
- ((TextView)buttonFullSearch).setTypeface(null, Typeface.BOLD);
-
buttonTitleSearch.setBackgroundColor(getResources().getColor(Utils.getThemedAttributeId(getActivity(),
R.attr.window_background_color)));
- ((TextView)buttonTitleSearch).setTypeface(null,
Typeface.NORMAL);
fullSearchFragment.show();
break;
default:
@@ -289,7 +240,6 @@
* too often. If the search is forced, the network request
is sent immediately.
*/
public void startSearch(String term, boolean force) {
- lastSearchForced = force;
if (!isSearchActive) {
openSearch();
}
@@ -306,12 +256,22 @@
}
}
+ if (!TextUtils.isEmpty(lastSearchedText) && !TextUtils.isEmpty(term)) {
+ if (term.startsWith(lastSearchedText)) {
+ // they just typed another character, so continue with
whatever search was
+ // last active
+ } else {
+ // it's an entirely new search term, so default to title search
+ showPanel(PANEL_TITLE_SEARCH);
+ }
+ }
+ lastSearchedText = term;
+
if (getActivePanel() == PANEL_TITLE_SEARCH) {
titleSearchFragment.startSearch(term, force);
} else if (getActivePanel() == PANEL_FULL_SEARCH) {
fullSearchFragment.startSearch(term, force);
}
- lastSearchedText = term;
}
/**
@@ -349,8 +309,6 @@
showPanel(PANEL_RECENT_SEARCHES);
}
}
- getView().findViewById(R.id.search_type_button_container)
- .setVisibility(fullSearchDisabled ? View.GONE : View.VISIBLE);
}
public void closeSearch() {
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
index e778b3d..7fb5242 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
@@ -22,6 +22,7 @@
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
+import java.util.ArrayList;
import java.util.List;
public class TitleSearchFragment extends Fragment {
@@ -55,16 +56,16 @@
}
/**
- * Interface for receiving an event when a Title search returns no results.
+ * Interface for receiving the number of results returned by Title search.
* Will be useful for automatically switching to a Full search
*/
- public interface OnNoResultsListener {
- void onNoResults();
+ public interface OnResultsCountListener {
+ void onResultsCount(int count);
}
- private OnNoResultsListener onNoResultsListener;
- public void setOnNoResultsListener(OnNoResultsListener listener) {
- onNoResultsListener = listener;
+ private OnResultsCountListener onResultsCountListener;
+ public void setOnResultsCountListener(OnResultsCountListener listener) {
+ onResultsCountListener = listener;
}
/**
@@ -178,6 +179,8 @@
return;
}
+ // clear the list of results
+ displayResults(new ArrayList<PageTitle>());
searchNoResults.setVisibility(View.GONE);
searchNetworkError.setVisibility(View.GONE);
@@ -185,6 +188,9 @@
List<PageTitle> cacheResult =
searchResultsCache.get(app.getPrimaryLanguage() + "-" + term);
if (cacheResult != null) {
+ if (onResultsCountListener != null) {
+ onResultsCountListener.onResultsCount(cacheResult.size());
+ }
displayResults(cacheResult);
return;
}
@@ -286,8 +292,8 @@
displayResults(result);
searchResultsCache.put(app.getPrimaryLanguage() + "-" +
mySearchTerm, result);
curSearchTask = null;
- if (result.size() == 0 && onNoResultsListener != null) {
- onNoResultsListener.onNoResults();
+ if (onResultsCountListener != null) {
+ onResultsCountListener.onResultsCount(result.size());
}
// scroll to top, but post it to the message queue,
because it should be done
// after the data set is updated.
--
To view, visit https://gerrit.wikimedia.org/r/179529
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf9ebc49299393a0afc17b87b4b8bc02f0ba74a6
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits