<commit_before>from sqlalchemy import sql

from app import db

def autocomplete(search_str):

    command = """(select first_name || ' ' || family_name as full_name, altmetric_score, orcid_id, id, 1 as sort_order
    from person
    where (first_name || ' ' || family_name) ilike '{str}%'
    order by altmetric_score desc
    limit 10)
    union
    (select first_name || ' ' || family_name as full_name, altmetric_score, orcid_id, id, 2 as sort_order
    from person
    where family_name ilike '{str}%'
    order by altmetric_score desc
    limit 10)
    order by sort_order, altmetric_score desc
    """.format(str=search_str)

    res = db.session.connection().execute(sql.text(command))
    rows = res.fetchall()
    ret = []
    prev_type = "there is no current type"


    for row in rows:
        ret.append({
            "name": row[0],
            "altmetric_score": row[1],
            "orcid_id": row[2],
            "id": row[3]
        })
<commit_msg>sort by buzz not altmetric_score<commit_after>from sqlalchemy import sql

from app import db

def autocomplete(search_str):

    command = """(select first_name || ' ' || family_name as full_name, buzz, orcid_id, id, 1 as sort_order
    from person
    where (first_name || ' ' || family_name) ilike '{str}%'
    order by buzz desc
    limit 10)
    union
    (select first_name || ' ' || family_name as full_name, buzz, orcid_id, id, 2 as sort_order
    from person
    where family_name ilike '{str}%'
    order by buzz desc
    limit 10)
    order by sort_order, buzz desc
    """.format(str=search_str)

    res = db.session.connection().execute(sql.text(command))
    rows = res.fetchall()
    ret = []
    prev_type = "there is no current type"


    for row in rows:
        ret.append({
            "name": row[0],
            "buzz": row[1],
            "orcid_id": row[2],
            "id": row[3]
        })

{'fraction_non_alphanumeric': 0.11671087533156499, 'fraction_numerical': 0.010610079575596816, 'mean_word_length': 2.6339113680154145, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6766775', 'n_tokens_mistral': 631, 'n_tokens_neox': 606, 'n_words': 182}