use of de.danoeh.antennapod.core.util.comparator.SearchResultValueComparator in project AntennaPod by AntennaPod.
the class FeedSearcher method performSearch.
/**
* Search through a feed, or all feeds, for episodes that match the query in either the title,
* chapter, or show notes. The search is first performed on titles, then chapters, and finally
* show notes. The list of resulting episodes also describes where the first match occurred
* (title, chapters, or show notes).
*
* @param context
* @param query search query
* @param selectedFeed feed to search, 0 to search through all feeds
* @return list of episodes containing the query
*/
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
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_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.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();
}
try {
for (int i = 0; i < tasks.size(); i++) {
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) {
e.printStackTrace();
}
Collections.sort(result, new SearchResultValueComparator());
return result;
}
Aggregations