(query)
return res
return one result that is most similar to query
return one result that is most similar to query
return one result that is most similar to query
def similar_search(query):
    """ return one result that is most similar to query"""
    ret = []
    query = query.strip().lower()
    for cand in all_titles:
        dist = levenshtein(query, cand[0])
        if dist < 3:
            ret.append((cand, dist))
    if not ret:
        return None
    res = max(ret, key=operator.itemgetter(1))

    db = get_mongo('paper')
    res = db.find_one({'_id': res[0][1]}, SEARCH_RETURN_FIELDS)
    return res
def similar_search ( query ) : ret = [ ] query = query . strip ( ) . lower ( ) for cand in all_titles : dist = levenshtein ( query , cand [ 0 ] ) if dist < 3 : ret . append ( ( cand , dist ) ) if not ret : return None res = max ( ret , key = operator . itemgetter ( 1 ) ) db = get_mongo ( 'paper' ) res = db . find_one ( { '_id' : res [ 0 ] [ 1 ] } , SEARCH_RETURN_FIELDS ) return res