From c0da3df8929b8a5822724d216a655bb1038118de Mon Sep 17 00:00:00 2001 From: orelogo Date: Sat, 25 Feb 2017 17:23:46 -0800 Subject: Organize search results lexicographically in addition to by where the query was matched --- .../core/util/comparator/SearchResultValueComparator.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'core') 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 { + /** + * 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; } } -- cgit v1.2.3