# Path: raggregate/queries/users.py
# def get_user_by_id(id):
# def get_user_by_name(name):
# def get_user_by_email(email):
# def get_user_by_token(token):
# def is_user_allowed_admin_action(user_id, target_id, request = None, target_class = 'user_post',):
# def get_followed_users(id):
# def get_user_votes(user_id, vote_type, submission_id=None):
# def create_temp_user(initial_pw = None):
# def fuzzify_date(d):
# def create_user(**kwargs):
# def login_user(request, u, password, bypass_password = False):
# def add_user_picture(orig_filename, new_prefix, up_dir, image_file):
# def send_email_to_user(request, to_email, title, body):
# def send_lost_password_verify_email(request, user):
# def generate_new_password(request, user):
# 
# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):


from pyramid.view import view_config
from raggregate.queries import users
from raggregate.queries import submission

@view_config(renderer='search.mak', route_name='search')
def search(request):
    r = request
    ses = r.session
    try:
        sc = request.registry.solr_conn
    except AttributeError:
        r.session['message'] = 'I could not find the search engine.'
        return {'code': 'ENOSOLR', 'success': False}
    search_term = r.params['term']
    q = sc.query()
    for term in search_term.split():
        q = q.query(term)
    res = q.execute()
    stories = []
    vds = []
    vote_dict = {}
    for r in res:

# Path: raggregate/queries/users.py
# def get_user_by_id(id):
# def get_user_by_name(name):
# def get_user_by_email(email):
# def get_user_by_token(token):
# def is_user_allowed_admin_action(user_id, target_id, request = None, target_class = 'user_post',):
# def get_followed_users(id):
# def get_user_votes(user_id, vote_type, submission_id=None):
# def create_temp_user(initial_pw = None):
# def fuzzify_date(d):
# def create_user(**kwargs):
# def login_user(request, u, password, bypass_password = False):
# def add_user_picture(orig_filename, new_prefix, up_dir, image_file):
# def send_email_to_user(request, to_email, title, body):
# def send_lost_password_verify_email(request, user):
# def generate_new_password(request, user):
# 
# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):


# Path: raggregate/views/search.py
from pyramid.view import view_config
from raggregate.queries import users
from raggregate.queries import submission


@view_config(renderer='search.mak', route_name='search')
def search(request):
    r = request
    ses = r.session
    try:
        sc = request.registry.solr_conn
    except AttributeError:
        r.session['message'] = 'I could not find the search engine.'
        return {'code': 'ENOSOLR', 'success': False}
    search_term = r.params['term']
    q = sc.query()
    for term in search_term.split():
        q = q.query(term)
    res = q.execute()
    stories = []
    vds = []
    vote_dict = {}
    for r in res:

        stories.append(submission.get_story_by_id(r['id']))