diff options
author | orelogo <orelogo@gmail.com> | 2017-02-25 17:23:46 -0800 |
---|---|---|
committer | orelogo <orelogo@gmail.com> | 2017-02-25 17:23:46 -0800 |
commit | c0da3df8929b8a5822724d216a655bb1038118de (patch) | |
tree | 4bff7743eaa46457eb9085431511632eb34c491e /core/src | |
parent | a1201cc95f4d8b7d8f6ce4a89aa675ee7111ab58 (diff) | |
download | AntennaPod-c0da3df8929b8a5822724d216a655bb1038118de.zip |
Organize search results lexicographically in addition to by where the
query was matched
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/comparator/SearchResultValueComparator.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/SearchResultValueComparator.java b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/SearchResultValueComparator.java index b16e0949d..d23901a45 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/SearchResultValueComparator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/SearchResultValueComparator.java @@ -1,14 +1,27 @@ package de.danoeh.antennapod.core.util.comparator; +import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.SearchResult; import java.util.Comparator; public class SearchResultValueComparator implements Comparator<SearchResult> { + /** + * Compare items based, first, on where they were found (ie. title, chapters, or show notes). + * If they were found in the same section, then compare based on the title, in lexicographic + * order. This is still not ideal since, for example, "#12 Example A" would be considered + * before "#8 Example B" due to the fact that "8" has a larger unicode value than "1" + */ @Override public int compare(SearchResult lhs, SearchResult rhs) { - return rhs.getValue() - lhs.getValue(); + int value = rhs.getValue() - lhs.getValue(); + if (value == 0 && lhs.getComponent() instanceof FeedItem && rhs.getComponent() instanceof FeedItem) { + String lhsTitle = ((FeedItem) lhs.getComponent()).getTitle(); + String rhsTitle = ((FeedItem) rhs.getComponent()).getTitle(); + return lhsTitle.compareTo(rhsTitle); + } + return value; } } |