Allow search provider names in preferred words

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…
This commit is contained in:
Ade
2014-05-11 19:35:41 +12:00
parent 8ab19f8121
commit 52a76e87ad
2 changed files with 14 additions and 5 deletions

View File

@@ -503,7 +503,7 @@
<div class="row">
<label>Preferred Words</label>
<input type="text" name="preferred_words" value="${config['preferred_words']}" size="50">
<small>Results with these words in the title will be preferred over results without them</small>
<small>Results with these words in the title will be preferred over results without them (search provider names can also be entered)</small>
</div>
<div class="row">
<label>Required Words</label>

View File

@@ -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