Make sure to preserve the original sort order (as returned by TheTVDB)

This commit is contained in:
Reinhard Pointner 2017-02-12 19:09:31 +08:00
parent f8da07a171
commit 2608cd7860
1 changed files with 3 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import static net.filebot.Settings.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -145,13 +146,13 @@ public final class WebServices {
} }
@Override @Override
public List<SearchResult> fetchSearchResult(final String query, final Locale locale) throws Exception { public List<SearchResult> fetchSearchResult(String query, Locale locale) throws Exception {
// run local search and API search in parallel // run local search and API search in parallel
Future<List<SearchResult>> apiSearch = requestThreadPool.submit(() -> TheTVDBClientWithLocalSearch.super.fetchSearchResult(query, locale)); Future<List<SearchResult>> apiSearch = requestThreadPool.submit(() -> TheTVDBClientWithLocalSearch.super.fetchSearchResult(query, locale));
Future<List<SearchResult>> localSearch = requestThreadPool.submit(() -> localIndex.get().search(query)); Future<List<SearchResult>> localSearch = requestThreadPool.submit(() -> localIndex.get().search(query));
// combine alias names into a single search results, and keep API search name as primary name // combine alias names into a single search results, and keep API search name as primary name
Map<Integer, SearchResult> results = Stream.concat(apiSearch.get().stream(), localSearch.get().stream()).collect(groupingBy(SearchResult::getId, collectingAndThen(toList(), group -> merge(group.get(0), group)))); Map<Integer, SearchResult> results = Stream.of(apiSearch.get(), localSearch.get()).flatMap(List::stream).collect(groupingBy(SearchResult::getId, LinkedHashMap::new, collectingAndThen(toList(), group -> merge(group.get(0), group))));
return sortBySimilarity(results.values(), singleton(query), getSeriesMatchMetric()); return sortBySimilarity(results.values(), singleton(query), getSeriesMatchMetric());
} }