@main.route('/results', methods=['GET', 'POST'])
def results_page():
    page = request.args.get('page')
    site = request.args.get('site')
    if (site and (site == 'jamesg.blog')):
        site = ''.join([x for x in site if (x.isalpha() or (x == '.'))])
        return redirect('/results?query=site:"{}"%20{}'.format(site, request.args.get('query')))
    special_result = False
    if (not request.args.get('query')):
        return redirect('/')
    query_with_handled_spaces = request.args.get('query').replace('--', '').replace('  ', ' ').strip()
    allowed_chars = [' ', '"', ':', '-', '/', '.', '=', ',']
    cleaned_value_for_query = ''.join((e for e in query_with_handled_spaces if (e.isalnum() or (e in allowed_chars)))).strip()
    (query_values_in_list, query_with_handled_spaces) = search_helpers.handle_advanced_search(query_with_handled_spaces)
    if (cleaned_value_for_query.startswith('xray https://') or cleaned_value_for_query.startswith('xray http://')):
        return redirect('https://xray.p3k.io/parse?url={}'.format(cleaned_value_for_query.replace('xray ', '')))
    session = requests.Session()
    if (cleaned_value_for_query == 'random'):
        random_site = session.get('https://es-indieweb-search.jamesg.blog/random?pw={}'.format(config.ELASTICSEARCH_PASSWORD)).json()['domain']
        return redirect('https://{}/'.format(random_site))
    if (not request.args.get('query')):
        return redirect('/')
    full_query_with_full_stops = ''.join((e for e in query_with_handled_spaces if (e.isalnum() or (e == ' ') or (e == '.'))))
    if (len(cleaned_value_for_query) == 0):
        return redirect('/')
    do_i_use = ''
    pagination = '0'
    if page:
        try:
            if (int(page) > 1):
                pagination = ((int(page) - 1) * 10)
        except:
            return redirect('/')
    else:
        page = 1
    order = 'score'
    minimal = 'false'
    if (request.args.get('order') == 'date_asc'):
        order = 'date_asc'
    elif (request.args.get('order') == 'date_desc'):
        order = 'date_desc'
    cleaned_value_for_query = cleaned_value_for_query.replace('what is', '')
    if (request.args.get('format') and ((request.args.get('format') == 'json_feed') or (request.args.get('format') == 'jf2'))):
        minimal = 'true'
    query_params = ''
    if query_values_in_list.get('site'):
        query_params += '&site={}'.format(query_values_in_list.get('site').replace('%', ''))
    if request.args.get('query').startswith('discover'):
        query_params += '&discover=true'
    if ('js:none' in request.args.get('query')):
        query_params += '&js=false'
    if query_values_in_list.get('category'):
        query_params += '&category={}'.format(query_values_in_list.get('category'))
    if query_values_in_list.get('mf2prop'):
        query_params += '&mf2_property={}'.format(query_values_in_list.get('mf2prop'))
    rows = session.get('https://es-indieweb-search.jamesg.blog/?pw={}&q={}&sort={}&from={}&minimal={}{}'.format(config.ELASTICSEARCH_PASSWORD, cleaned_value_for_query.replace('who is', '').replace('code', '').replace('discover ', '').strip(), order, str(pagination), minimal, query_params)).json()
    num_of_results = rows['hits']['total']['value']
    rows = rows['hits']['hits']
    for r in rows:
        if r['_source'].get('h_card'):
            r['_source']['h_card'] = json.loads(r['_source']['h_card'])
        else:
            r['_source']['h_card'] = None
    cleaned_value = cleaned_value_for_query.lower()
    if (page == 1):
        (do_i_use, special_result) = choose_direct_answer.choose_featured_snippet(cleaned_value, cleaned_value_for_query, rows, special_result, full_query_with_full_stops, session, nlp)
    if (len(rows) == 0):
        out_of_bounds_page = True
        final_query = cleaned_value_for_query
    else:
        out_of_bounds_page = False
        suggestion = False
        final_query = ''
    if (('random aeropress' in cleaned_value) or (('generate aeropress' in cleaned_value) and (request.args.get('type') != 'image'))):
        special_result = search_result_features.aeropress_recipe()
    format = request.args.get('format')
    if (format == 'json_feed'):
        json_feed = search_page_feeds.process_json_feed(rows, cleaned_value, page, format)
        return json_feed
    elif (format == 'jf2'):
        jf2_feed = search_page_feeds.process_jf2_feed(rows)
        return jf2_feed
    elif (format == 'rss'):
        rss_feed = search_page_feeds.process_rss_feed(rows, cleaned_value, page, format)
        return rss_feed
    elif (format == 'direct_serp_json'):
        if special_result:
            return jsonify({'text': do_i_use, 'featured_serp': special_result})
        else:
            return jsonify({'message': 'no custom serp available on this search'})
    elif (format == 'results_page_json'):
        return jsonify({'results': [r['_source'] for r in rows]})
    if ((not special_result) and (not do_i_use) and (int(num_of_results) == 0)):
        num_of_results = 0
        out_of_bounds_page = True
    else:
        out_of_bounds_page = False
    return render_template('search/results.html', results=rows, number_of_results=int(num_of_results), page=int(page), page_count=int(math.ceil((num_of_results / 10))), query=cleaned_value, results_type=request.args.get('type'), out_of_bounds_page=out_of_bounds_page, ordered_by=request.args.get('order'), base_results_query=('/results?query=' + cleaned_value_for_query), corrected_text=final_query, suggestion_made=suggestion, special_result=special_result, do_i_use=do_i_use, title="Search results for '{}' query".format(cleaned_value))
@main.route('/results', methods=['GET', 'POST'])
def results_page():
    page = request.args.get('page')
    site = request.args.get('site')
    if (site and (site == 'jamesg.blog')):
        site = .join([x for x in site if (x.isalpha() or (x == '.'))])
        return redirect('/results?query=site:"{}"%20{}'.format(site, request.args.get('query')))
    special_result = False
    if (not request.args.get('query')):
        return redirect('/')
    query_with_handled_spaces = request.args.get('query').replace('--', ).replace('  ', ' ').strip()
    allowed_chars = [' ', '"', ':', '-', '/', '.', '=', ',']
    cleaned_value_for_query = .join((e for e in query_with_handled_spaces if (e.isalnum() or (e in allowed_chars)))).strip()
    (query_values_in_list, query_with_handled_spaces) = search_helpers.handle_advanced_search(query_with_handled_spaces)
    if (cleaned_value_for_query.startswith('xray https://') or cleaned_value_for_query.startswith('xray http://')):
        return redirect('https://xray.p3k.io/parse?url={}'.format(cleaned_value_for_query.replace('xray ', )))
    session = requests.Session()
    if (cleaned_value_for_query == 'random'):
        random_site = session.get('https://es-indieweb-search.jamesg.blog/random?pw={}'.format(config.ELASTICSEARCH_PASSWORD)).json()['domain']
        return redirect('https://{}/'.format(random_site))
    if (not request.args.get('query')):
        return redirect('/')
    full_query_with_full_stops = .join((e for e in query_with_handled_spaces if (e.isalnum() or (e == ' ') or (e == '.'))))
    if (len(cleaned_value_for_query) == 0):
        return redirect('/')
    do_i_use = 
    pagination = '0'
    if page:
        try:
            if (int(page) > 1):
                pagination = ((int(page) - 1) * 10)
        except:
            return redirect('/')
    else:
        page = 1
    order = 'score'
    minimal = 'false'
    if (request.args.get('order') == 'date_asc'):
        order = 'date_asc'
    elif (request.args.get('order') == 'date_desc'):
        order = 'date_desc'
    cleaned_value_for_query = cleaned_value_for_query.replace('what is', )
    if (request.args.get('format') and ((request.args.get('format') == 'json_feed') or (request.args.get('format') == 'jf2'))):
        minimal = 'true'
    query_params = 
    if query_values_in_list.get('site'):
        query_params += '&site={}'.format(query_values_in_list.get('site').replace('%', ))
    if request.args.get('query').startswith('discover'):
        query_params += '&discover=true'
    if ('js:none' in request.args.get('query')):
        query_params += '&js=false'
    if query_values_in_list.get('category'):
        query_params += '&category={}'.format(query_values_in_list.get('category'))
    if query_values_in_list.get('mf2prop'):
        query_params += '&mf2_property={}'.format(query_values_in_list.get('mf2prop'))
    rows = session.get('https://es-indieweb-search.jamesg.blog/?pw={}&q={}&sort={}&from={}&minimal={}{}'.format(config.ELASTICSEARCH_PASSWORD, cleaned_value_for_query.replace('who is', ).replace('code', ).replace('discover ', ).strip(), order, str(pagination), minimal, query_params)).json()
    num_of_results = rows['hits']['total']['value']
    rows = rows['hits']['hits']
    for r in rows:
        if r['_source'].get('h_card'):
            r['_source']['h_card'] = json.loads(r['_source']['h_card'])
        else:
            r['_source']['h_card'] = None
    cleaned_value = cleaned_value_for_query.lower()
    if (page == 1):
        (do_i_use, special_result) = choose_direct_answer.choose_featured_snippet(cleaned_value, cleaned_value_for_query, rows, special_result, full_query_with_full_stops, session, nlp)
    if (len(rows) == 0):
        out_of_bounds_page = True
        final_query = cleaned_value_for_query
    else:
        out_of_bounds_page = False
        suggestion = False
        final_query = 
    if (('random aeropress' in cleaned_value) or (('generate aeropress' in cleaned_value) and (request.args.get('type') != 'image'))):
        special_result = search_result_features.aeropress_recipe()
    format = request.args.get('format')
    if (format == 'json_feed'):
        json_feed = search_page_feeds.process_json_feed(rows, cleaned_value, page, format)
        return json_feed
    elif (format == 'jf2'):
        jf2_feed = search_page_feeds.process_jf2_feed(rows)
        return jf2_feed
    elif (format == 'rss'):
        rss_feed = search_page_feeds.process_rss_feed(rows, cleaned_value, page, format)
        return rss_feed
    elif (format == 'direct_serp_json'):
        if special_result:
            return jsonify({'text': do_i_use, 'featured_serp': special_result})
        else:
            return jsonify({'message': 'no custom serp available on this search'})
    elif (format == 'results_page_json'):
        return jsonify({'results': [r['_source'] for r in rows]})
    if ((not special_result) and (not do_i_use) and (int(num_of_results) == 0)):
        num_of_results = 0
        out_of_bounds_page = True
    else:
        out_of_bounds_page = False
    return render_template('search/results.html', results=rows, number_of_results=int(num_of_results), page=int(page), page_count=int(math.ceil((num_of_results / 10))), query=cleaned_value, results_type=request.args.get('type'), out_of_bounds_page=out_of_bounds_page, ordered_by=request.args.get('order'), base_results_query=('/results?query=' + cleaned_value_for_query), corrected_text=final_query, suggestion_made=suggestion, special_result=special_result, do_i_use=do_i_use, title="Search results for '{}' query".format(cleaned_value))