diff options
author | orelogo <orelogo@gmail.com> | 2016-07-13 13:25:13 -0400 |
---|---|---|
committer | orelogo <orelogo@gmail.com> | 2016-07-13 13:43:49 -0400 |
commit | b5928194d5ede85d519fdebc9b56c5c322b5b137 (patch) | |
tree | 3c04607a11caacea1c49397d54ef6552effdbede /core/src | |
parent | 3863a5d19007deb62c97c07ee288cc86cca6f7ec (diff) | |
download | AntennaPod-b5928194d5ede85d519fdebc9b56c5c322b5b137.zip |
Search Results: prevent duplicate feed items
- title results take precedence over shownotes results
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java index b88d774a2..7be851944 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java @@ -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,7 +47,9 @@ public class FeedSearcher { FutureTask<List<FeedItem>> task = tasks.get(i); List<FeedItem> items = task.get(); for (FeedItem item : items) { - result.add(new SearchResult(item, values[i], subtitles[i])); + if (result.isEmpty() || !isDuplicate(result, item)) { + result.add(new SearchResult(item, values[i], subtitles[i])); + } } } @@ -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; + } } |