def search_page(page): page = int(page) - 1 query_string = request.args.get('q') if not query_string or len(query_string) == 0: results = {} else: print('Searching for', query_string) api = SearchAPI(ELASTIC_URL) results = api.search(query_string, INDEX_NAME, DOCUMENT_TYPE, 10, 10*page) if 'error' in results: results = {} return render_template('result_items.html', results=results['hits']['hits'])
def search(): query_string = request.args.get('q') if not query_string or len(query_string) == 0: return redirect(url_for('home')) print('Searching for', query_string) api = SearchAPI(ELASTIC_URL) results = api.search(query_string, INDEX_NAME, DOCUMENT_TYPE, 10) # import random if 'error' not in results: # for r in results['hits']['hits']: # r['_source']['cluster'] = random.randint(0,3) clusters = set(map(lambda res: res['_source']['cluster'], results['hits']['hits'])) return render_template('results.html', query=query_string, total_results=results['hits']['total'], results=results['hits']['hits'], duration='{} seconds'.format(results['took']/1000.0), topics=map(_get_cluster_data, clusters) ) else: return render_template('sorry.html', extra_data=json.dumps(results, indent=True))