forked from platypush/platypush
- Show Spotify results first from MPD search, if available
- More granular calculation of the match score
This commit is contained in:
parent
400943b74b
commit
87fb8855b7
2 changed files with 11 additions and 6 deletions
|
@ -118,12 +118,12 @@ class Event(Message):
|
||||||
if event_token == condition_token:
|
if event_token == condition_token:
|
||||||
event_tokens.pop(0)
|
event_tokens.pop(0)
|
||||||
condition_tokens.pop(0)
|
condition_tokens.pop(0)
|
||||||
result.score += 1
|
result.score += 1.5
|
||||||
elif re.search(condition_token, event_token):
|
elif re.search(condition_token, event_token):
|
||||||
m = re.search('({})'.format(condition_token), event_token)
|
m = re.search('({})'.format(condition_token), event_token)
|
||||||
if m.group(1):
|
if m.group(1):
|
||||||
event_tokens.pop(0)
|
event_tokens.pop(0)
|
||||||
result.score += 1
|
result.score += 1.25
|
||||||
|
|
||||||
condition_tokens.pop(0)
|
condition_tokens.pop(0)
|
||||||
else:
|
else:
|
||||||
|
@ -132,7 +132,7 @@ class Event(Message):
|
||||||
argname = m.group(1)
|
argname = m.group(1)
|
||||||
if argname not in result.parsed_args:
|
if argname not in result.parsed_args:
|
||||||
result.parsed_args[argname] = event_token
|
result.parsed_args[argname] = event_token
|
||||||
result.score += 1
|
result.score += 1.0
|
||||||
else:
|
else:
|
||||||
result.parsed_args[argname] += ' ' + event_token
|
result.parsed_args[argname] += ' ' + event_token
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class Event(Message):
|
||||||
|
|
||||||
event_tokens.pop(0)
|
event_tokens.pop(0)
|
||||||
else:
|
else:
|
||||||
result.score -= 1
|
result.score -= 1.0
|
||||||
event_tokens.pop(0)
|
event_tokens.pop(0)
|
||||||
|
|
||||||
# It's a match if all the tokens in the condition string have been satisfied
|
# It's a match if all the tokens in the condition string have been satisfied
|
||||||
|
|
|
@ -130,8 +130,13 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
output=self.client.findadd(*filter, *args, **kwargs))
|
output=self.client.findadd(*filter, *args, **kwargs))
|
||||||
|
|
||||||
def search(self, filter, *args, **kwargs):
|
def search(self, filter, *args, **kwargs):
|
||||||
return Response(
|
items = self.client.search(*filter, *args, **kwargs)
|
||||||
output=self.client.search(*filter, *args, **kwargs))
|
|
||||||
|
# Spotify results first
|
||||||
|
items = sorted(items, key=lambda item:
|
||||||
|
0 if item['file'].startswith('spotify:') else 1)
|
||||||
|
|
||||||
|
return Response(output=items)
|
||||||
|
|
||||||
def searchadd(self, filter, *args, **kwargs):
|
def searchadd(self, filter, *args, **kwargs):
|
||||||
return Response(
|
return Response(
|
||||||
|
|
Loading…
Reference in a new issue