Search Results: prevent duplicate feed items
- title results take precedence over shownotes results
This commit is contained in:
parent
3863a5d190
commit
b5928194d5
|
@ -25,19 +25,20 @@ public class FeedSearcher {
|
|||
*/
|
||||
public static List<SearchResult> performSearch(final Context context,
|
||||
final String query, final long selectedFeed) {
|
||||
final int values[] = {0, 0, 1, 2};
|
||||
final String[] subtitles = {context.getString(R.string.found_in_shownotes_label),
|
||||
context.getString(R.string.found_in_shownotes_label),
|
||||
final int values[] = {2, 1, 0, 0};
|
||||
final String[] subtitles = {context.getString(R.string.found_in_title_label),
|
||||
context.getString(R.string.found_in_chapters_label),
|
||||
context.getString(R.string.found_in_title_label)};
|
||||
context.getString(R.string.found_in_shownotes_label),
|
||||
context.getString(R.string.found_in_shownotes_label)};
|
||||
|
||||
List<SearchResult> result = new ArrayList<>();
|
||||
|
||||
List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
|
||||
tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
|
||||
tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
|
||||
|
||||
for (FutureTask<List<FeedItem>> task : tasks) {
|
||||
task.run();
|
||||
}
|
||||
|
@ -46,8 +47,10 @@ public class FeedSearcher {
|
|||
FutureTask<List<FeedItem>> task = tasks.get(i);
|
||||
List<FeedItem> items = task.get();
|
||||
for (FeedItem item : items) {
|
||||
if (result.isEmpty() || !isDuplicate(result, item)) {
|
||||
result.add(new SearchResult(item, values[i], subtitles[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
|
@ -56,4 +59,20 @@ public class FeedSearcher {
|
|||
Collections.sort(result, new SearchResultValueComparator());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the feed item is already in the search result list.
|
||||
*
|
||||
* @param result list of search results
|
||||
* @param item feed item to validate
|
||||
* @return true if the feed item is already in the results
|
||||
*/
|
||||
private static boolean isDuplicate(List<SearchResult> result, FeedItem item) {
|
||||
for (SearchResult resultItem : result) {
|
||||
if (resultItem.getComponent().getId() == item.getId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue