From 3af9e2ce6596bcb870e789c4a3aedb8bc4743bbe Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 22 Apr 2014 07:14:11 -0700 Subject: [PATCH] New show searches now try and return exact matches first then next best, search speed vastly improved as well. --- sickbeard/webserve.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index de74663d..56cb8bb8 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1961,7 +1961,7 @@ class NewHomeAddShows: if not lang or lang == 'null': lang = "en" - results = [] + final_results = [] nameUTF8 = name.encode('utf-8') @@ -1978,6 +1978,8 @@ class NewHomeAddShows: # Query Indexers for each search term and build the list of results for indexer in indexers: + results = [] + lINDEXER_API_PARMS = sickbeard.indexerApi(indexer).api_params.copy() lINDEXER_API_PARMS['custom_ui'] = classes.AllShowsListUI t = sickbeard.indexerApi(indexer).indexer(**lINDEXER_API_PARMS) @@ -1989,18 +1991,20 @@ class NewHomeAddShows: search = [search] # add search results - results += list([sickbeard.indexerApi(indexer).name, int(sickbeard.indexerApi(indexer).config['id']), - sickbeard.indexerApi(indexer).config["show_url"], int(x['id']), x['seriesname'], - x['firstaired']] for x in search if x['firstaired']) + results += search except: continue + final_results += list([sickbeard.indexerApi(indexer).name, int(sickbeard.indexerApi(indexer).config['id']), + sickbeard.indexerApi(indexer).config["show_url"], int(x['id']), x['seriesname'], + x['firstaired']] for x in results if re.search(keywords[0], x['seriesname'], flags=re.I) and x['firstaired']) + # remove duplicates and sort by firstaired - results = sorted(results, reverse=True, key=operator.itemgetter(5)) - results = list(results for results, _ in itertools.groupby(results)) + final_results = sorted(final_results, reverse=True, key=operator.itemgetter(5)) + final_results = list(final_results for final_results, _ in itertools.groupby(final_results)) lang_id = sickbeard.indexerApi().config['langabbv_to_id'][lang] - return json.dumps({'results': results, 'langid': lang_id}) + return json.dumps({'results': final_results, 'langid': lang_id}) @cherrypy.expose def massAddTable(self, rootDir=None):