Move static search ranking from DatabaseResultLoader to Search Adapter.

This will avoid unnecessary static ranking if smart ranking is used.

Since loader does not need to provided sorted collection of results,
the loading data type has changed from List<> to Set<>. This will also
faster lookup in the Adapter.

Fixes: 38447799
Test: make RunSettingsRoboTests

Change-Id: I448b29bd4e8700c8ec4b5766cbeab4b3087ae39a
This commit is contained in:
Soroosh Mariooryad
2017-05-25 14:15:00 -07:00
parent 21aab578c9
commit 683ccdf97b
10 changed files with 100 additions and 76 deletions

View File

@@ -45,7 +45,10 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
@@ -224,17 +227,19 @@ public class DatabaseResultLoaderTest {
}
@Test
public void testSpecialCaseTwoWords_firstWordMatches_ranksHigher() {
public void testSpecialCaseTwoWords_multipleResults() {
final String caseOne = "Apple pear";
final String caseTwo = "Banana apple";
insertSpecialCase(caseOne);
insertSpecialCase(caseTwo);
DatabaseResultLoader loader = new DatabaseResultLoader(mContext, "App", null);
List<? extends SearchResult> results = loader.loadInBackground();
assertThat(results.get(0).title).isEqualTo(caseOne);
assertThat(results.get(1).title).isEqualTo(caseTwo);
assertThat(results.get(0).rank).isLessThan(results.get(1).rank);
Set<? extends SearchResult> results = loader.loadInBackground();
Set<CharSequence> expectedTitles = new HashSet<>(Arrays.asList(caseOne, caseTwo));
Set<CharSequence> actualTitles = new HashSet<>();
for (SearchResult result : results) {
actualTitles.add(result.title);
}
assertThat(actualTitles).isEqualTo(expectedTitles);
}
private void insertSpecialCase(String specialCase) {