From 52a76e87adcd33ab5cb873e787c9fa8465e19e12 Mon Sep 17 00:00:00 2001 From: Ade Date: Sun, 11 May 2014 19:35:41 +1200 Subject: [PATCH] Allow search provider names in preferred words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds to the priority if the word matches the search provider. The provider priority is weighted based on position in list. Preferred words in title take precedence over preferred providers. Would be great if we could do something like sb, so until then… --- data/interfaces/default/config.html | 2 +- headphones/searcher.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 9e48eadb..5ee7a95b 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -503,7 +503,7 @@
- Results with these words in the title will be preferred over results without them + Results with these words in the title will be preferred over results without them (search provider names can also be entered)
diff --git a/headphones/searcher.py b/headphones/searcher.py index 8c2a699d..d733a2f3 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -151,11 +151,20 @@ def sort_search_results(resultlist, album, new): # Add a priority if it has any of the preferred words temp_list = [] + preferred_words = None + if headphones.PREFERRED_WORDS: + preferred_words = helpers.split_string(headphones.PREFERRED_WORDS) for result in resultlist: - if headphones.PREFERRED_WORDS and any(word.lower() in result[0].lower() for word in helpers.split_string(headphones.PREFERRED_WORDS)): - temp_list.append((result[0],result[1],result[2],result[3],result[4],1)) - else: - temp_list.append((result[0],result[1],result[2],result[3],result[4],0)) + priority = 0 + if preferred_words: + if any(word.lower() in result[0].lower() for word in preferred_words): + priority = 1 + # add a search provider priority (weighted based on position) + i = next((i for i, word in enumerate(preferred_words) if word in result[3].lower()), None) + if i != None: + priority += round((len(preferred_words) - i) / float(len(preferred_words)),2) + + temp_list.append((result[0],result[1],result[2],result[3],result[4],priority)) resultlist = temp_list