From 50dd85276ca3507cfe4d9ec421aa0c406623ac01 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 4 Feb 2020 23:50:38 +0100 Subject: [PATCH] Fixed search returning duplicates --- .../de/danoeh/antennapod/core/storage/FeedSearcher.java | 8 +------- .../de/danoeh/antennapod/core/storage/PodDBAdapter.java | 9 ++------- .../danoeh/antennapod/core/storage/SearchLocation.java | 4 +--- 3 files changed, 4 insertions(+), 17 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 1d9e33d0e..6d6359a42 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 @@ -47,16 +47,10 @@ public class FeedSearcher { SearchLocation location; if (safeContains(item.getTitle(), query)) { location = SearchLocation.TITLE; - } else if (safeContains(item.getContentEncoded(), query)) { - location = SearchLocation.SHOWNOTES; - } else if (safeContains(item.getDescription(), query)) { - location = SearchLocation.SHOWNOTES; } else if (safeContains(item.getChapters(), query)) { location = SearchLocation.CHAPTERS; - } else if (safeContains(item.getFeed().getAuthor(), query)) { - location = SearchLocation.AUTHORS; } else { - location = SearchLocation.FEED; + location = SearchLocation.SHOWNOTES; } result.add(new SearchResult(item, location)); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 17b79a3da..48af7def0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -1273,20 +1273,15 @@ public class PodDBAdapter { queryFeedId = "1 = 1"; } - String query = "SELECT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS + String query = "SELECT DISTINCT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS + " LEFT JOIN " + TABLE_NAME_SIMPLECHAPTERS + " ON " + TABLE_NAME_SIMPLECHAPTERS + "." + KEY_FEEDITEM + "=" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID - + " LEFT JOIN " + TABLE_NAME_FEEDS - + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED - + "=" + TABLE_NAME_FEEDS + "." + KEY_ID + " WHERE " + queryFeedId + " AND (" + TABLE_NAME_FEED_ITEMS + "." + KEY_DESCRIPTION + " LIKE '%" + preparedQuery + "%' OR " + TABLE_NAME_FEED_ITEMS + "." + KEY_CONTENT_ENCODED + " LIKE '%" + preparedQuery + "%' OR " + TABLE_NAME_FEED_ITEMS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%' OR " - + TABLE_NAME_SIMPLECHAPTERS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%' OR " - + TABLE_NAME_FEEDS + "." + KEY_AUTHOR + " LIKE '%" + preparedQuery + "%' OR " - + TABLE_NAME_FEEDS + "." + KEY_FEED_IDENTIFIER + " LIKE '%" + preparedQuery + "%'" + + TABLE_NAME_SIMPLECHAPTERS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%'" + ") ORDER BY " + KEY_PUBDATE + " DESC " + "LIMIT 500"; return db.rawQuery(query, null); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/SearchLocation.java b/core/src/main/java/de/danoeh/antennapod/core/storage/SearchLocation.java index fabe85b2c..078797bda 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/SearchLocation.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/SearchLocation.java @@ -6,9 +6,7 @@ import de.danoeh.antennapod.core.R; public enum SearchLocation { TITLE(R.string.found_in_title_label), CHAPTERS(R.string.found_in_chapters_label), - SHOWNOTES(R.string.found_in_shownotes_label), - AUTHORS(R.string.found_in_authors_label), - FEED(R.string.found_in_feeds_label); + SHOWNOTES(R.string.found_in_shownotes_label); private int description; SearchLocation(@StringRes int description) {