Add scoring based on the string distance
This commit is contained in:
parent
55a2c54ab6
commit
a34d56045f
3 changed files with 7 additions and 1 deletions
|
@ -8,6 +8,7 @@ from auth.auth_context import get_authenticated_user
|
|||
from auth import scopes
|
||||
from app import avatar, get_app_url
|
||||
from operator import itemgetter
|
||||
from stringscore import liquidmetal
|
||||
|
||||
import math
|
||||
|
||||
|
@ -164,7 +165,7 @@ class ConductSearch(ApiResource):
|
|||
'name': repo.name,
|
||||
'description': repo.description,
|
||||
'is_public': repo.visibility.name == 'public',
|
||||
'score': math.log(matching_repo_counts.get(repo.id, 1), 10),
|
||||
'score': math.log(matching_repo_counts.get(repo.id, 1), 10) or 1,
|
||||
'href': '/repository/' + repo.namespace_user.username + '/' + repo.name
|
||||
})
|
||||
|
||||
|
@ -173,6 +174,9 @@ class ConductSearch(ApiResource):
|
|||
for entity in matching_entities:
|
||||
results.append(entity_view(entity))
|
||||
|
||||
for result in results:
|
||||
result['score'] = result['score'] * liquidmetal.score(result['name'], prefix)
|
||||
|
||||
return {'results': sorted(results, key=itemgetter('score'), reverse=True)}
|
||||
|
||||
|
||||
|
|
|
@ -48,3 +48,4 @@ pygpgme
|
|||
cachetools
|
||||
mock
|
||||
psutil
|
||||
stringscore
|
|
@ -54,6 +54,7 @@ redis==2.10.3
|
|||
reportlab==2.7
|
||||
requests==2.5.1
|
||||
six==1.9.0
|
||||
stringscore==0.10.0
|
||||
stripe==1.20.1
|
||||
trollius==1.0.4
|
||||
tzlocal==1.1.2
|
||||
|
|
Reference in a new issue