From 872389d055fee1a82c48ab518472d3514226b886 Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 25 Mar 2014 11:01:21 -0700 Subject: [PATCH] New show search code changed to optimize for quicker searches Increased mainDB version to 28 --- sickbeard/databases/mainDB.py | 2 +- sickbeard/webserve.py | 47 +++++++++-------------------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index 0cf1df31..87f9aa97 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -27,7 +27,7 @@ from sickbeard import encodingKludge as ek from sickbeard.name_parser.parser import NameParser, InvalidNameException MIN_DB_VERSION = 9 # oldest db version we support migrating from -MAX_DB_VERSION = 27 +MAX_DB_VERSION = 28 class MainSanityCheck(db.DBSanityCheck): diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 56ee8b14..fb3e8e31 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1982,44 +1982,21 @@ class NewHomeAddShows: # Query Indexers for each search term and build the list of results for i in indexers: - def searchShows(): - results = [] + lINDEXER_API_PARMS = {'indexer': i, 'custom_ui': classes.AllShowsListUI} + t = sickbeard.indexerApi(**lINDEXER_API_PARMS) - lINDEXER_API_PARMS = {'indexer': i, 'custom_ui': classes.AllShowsListUI} - t = sickbeard.indexerApi(**lINDEXER_API_PARMS) + for searchTerm in keywords: + try: + search = t[searchTerm] + if isinstance(search, dict): + search = [search] - for searchTerm in keywords: - try: - search = t[searchTerm] - if isinstance(search, dict): - search = [search] + # add search results + results += [[t.name, t.config['id'], t.config["show_url"], int(x['id']), x['seriesname'], + x['firstaired']] for x in search] - # add search results - result = [[t.name, t.config['id'], t.config["show_url"], int(x['id']), x['seriesname'], - x['firstaired']] for x in search if nameUTF8.lower() in x['seriesname'].lower()] - - # see if we have any matches - if len(result) > 0: - # add result to list of found shows - results += result - - # search through result to see if we have a exact match - for show in result: - # cleanup the series name - seriesname = show[4].encode('utf-8').translate(None, string.punctuation) - - # check if we got a exact match - if nameUTF8.lower() == seriesname.lower(): - return results - - except Exception, e: - continue - - # finished searching a indexer so return the results - return results - - # search indexers for shows - results += searchShows() + except Exception, e: + continue # remove duplicates results = list(results for results, _ in itertools.groupby(results))