aboutsummaryrefslogtreecommitdiff
path: root/api/social/search.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-16 16:57:26 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-16 16:57:26 +0200
commit07c2b124e4348b15f1e5ec18c6cdfd77248c6bc8 (patch)
treee4a29123d3ebedc1d25500390c904c66b3b02489 /api/social/search.py
parentaa2c999702dadba2afbcf2be9f597f890aafcc87 (diff)
spaces > tabs in python :(
Diffstat (limited to 'api/social/search.py')
-rw-r--r--api/social/search.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/api/social/search.py b/api/social/search.py
index f0ce8a2..c0ef312 100644
--- a/api/social/search.py
+++ b/api/social/search.py
@@ -8,26 +8,26 @@ search = Blueprint('search', __name__)
@search.route('/search', methods=['POST'])
def index():
- data_string = request.data or "{}"
- data = json.loads(data_string)
- query = data.get("query") or ""
- if not query: return "", 400
- if len(query) < 3: return "", 403
-
- # use levenshtein with max distance 3 to search for users
- #TODO: use mysql and sort by best match
- results = cursor.execute(
- "select user_id from users where levenshtein(lower(username), lower(?), 3)",
- [query]
- ).fetchmany(20)
-
- formatted = {"results": []}
-
- # get user_id for each result to prevent repeat user/info requests
- for user in results:
- formatted["results"].append(format_user(user[0]))
-
- return formatted, 200
+ data_string = request.data or "{}"
+ data = json.loads(data_string)
+ query = data.get("query") or ""
+ if not query: return "", 400
+ if len(query) < 3: return "", 403
+
+ # use levenshtein with max distance 3 to search for users
+ #TODO: use mysql and sort by best match
+ results = cursor.execute(
+ "select user_id from users where levenshtein(lower(username), lower(?), 3)",
+ [query]
+ ).fetchmany(20)
+
+ formatted = {"results": []}
+
+ # get user_id for each result to prevent repeat user/info requests
+ for user in results:
+ formatted["results"].append(format_user(user[0]))
+
+ return formatted, 200
dynamic_route = ["/social", search]