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