Skip to content

Commit

Permalink
Return results from the first db that has results
Browse files Browse the repository at this point in the history
This patch returns results from the first database that has results.
This is done for performance and to avoid having to sort the results.
  • Loading branch information
ahmedre committed May 21, 2017
1 parent 5870984 commit 7873500
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
Expand All @@ -25,7 +24,6 @@
import com.quran.labs.androidquran.util.QuranSettings;
import com.quran.labs.androidquran.util.QuranUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
Expand Down Expand Up @@ -201,7 +199,6 @@ private Cursor search(String query, List<LocalTranslation> translations) {
int start = haveArabic ? -1 : 0;
int total = translations.size() + (haveArabic ? 1 : 0);

List<Cursor> cursorList = new ArrayList<>();
for (int i = start; i < total; i++) {
String databaseName;
if (i < 0) {
Expand All @@ -221,16 +218,11 @@ private Cursor search(String query, List<LocalTranslation> translations) {
}

Cursor cursor = search(query, databaseName, true);
if (cursor != null) {
cursorList.add(cursor);
if (cursor != null && cursor.getCount() > 0) {
return cursor;
}
}

Cursor[] cursors = new Cursor[cursorList.size()];
for (int i = 0, size = cursorList.size(); i < size; i++) {
cursors[i] = cursorList.get(i);
}
return new MergeCursor(cursors);
return null;
}

private Cursor search(String query, String databaseName, boolean wantSnippets) {
Expand Down

0 comments on commit 7873500

Please sign in to comment.