From a34d56045f4b5e31e90b2cf53df277dc5669d56b Mon Sep 17 00:00:00 2001
From: Joseph Schorr <joseph.schorr@coreos.com>
Date: Tue, 7 Apr 2015 12:32:23 -0400
Subject: [PATCH] Add scoring based on the string distance

---
 endpoints/api/search.py | 6 +++++-
 requirements-nover.txt  | 1 +
 requirements.txt        | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/endpoints/api/search.py b/endpoints/api/search.py
index 718a19669..4e6288875 100644
--- a/endpoints/api/search.py
+++ b/endpoints/api/search.py
@@ -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)}
 
 
diff --git a/requirements-nover.txt b/requirements-nover.txt
index 5eb570581..055d38875 100644
--- a/requirements-nover.txt
+++ b/requirements-nover.txt
@@ -48,3 +48,4 @@ pygpgme
 cachetools
 mock
 psutil
+stringscore
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 5b5f061a2..2ba8fffe2 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -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