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 auth import scopes
|
||||||
from app import avatar, get_app_url
|
from app import avatar, get_app_url
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from stringscore import liquidmetal
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ class ConductSearch(ApiResource):
|
||||||
'name': repo.name,
|
'name': repo.name,
|
||||||
'description': repo.description,
|
'description': repo.description,
|
||||||
'is_public': repo.visibility.name == 'public',
|
'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
|
'href': '/repository/' + repo.namespace_user.username + '/' + repo.name
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -173,6 +174,9 @@ class ConductSearch(ApiResource):
|
||||||
for entity in matching_entities:
|
for entity in matching_entities:
|
||||||
results.append(entity_view(entity))
|
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)}
|
return {'results': sorted(results, key=itemgetter('score'), reverse=True)}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,3 +48,4 @@ pygpgme
|
||||||
cachetools
|
cachetools
|
||||||
mock
|
mock
|
||||||
psutil
|
psutil
|
||||||
|
stringscore
|
|
@ -54,6 +54,7 @@ redis==2.10.3
|
||||||
reportlab==2.7
|
reportlab==2.7
|
||||||
requests==2.5.1
|
requests==2.5.1
|
||||||
six==1.9.0
|
six==1.9.0
|
||||||
|
stringscore==0.10.0
|
||||||
stripe==1.20.1
|
stripe==1.20.1
|
||||||
trollius==1.0.4
|
trollius==1.0.4
|
||||||
tzlocal==1.1.2
|
tzlocal==1.1.2
|
||||||
|
|
Reference in a new issue