Skip to content

Commit

Permalink
add try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
joedanz committed May 8, 2015
1 parent 61d79a1 commit 06258b5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/__init__.py
Expand Up @@ -59,13 +59,19 @@ def add_document():
def search():
search_term = request.form['search']
#res = es.search(index="gutenberg", body={"query": {"match_all": {}}})
res = es.search(index="gutenberg", size=20, body={"query": {"multi_match" : { "query": search_term, "fields": ["title", "content"] }}})
return render_template('results.html', res=res, term=search_term)
try:
res = es.search(index="gutenberg", size=20, body={"query": {"multi_match" : { "query": search_term, "fields": ["title", "content"] }}})
return render_template('results.html', res=res, term=search_term)
except:
return render_template('health.html', res="ERROR: Can't find any ElasticSearch servers.")

@app.route('/search/<search_term>', methods=['GET'])
def search_history(search_term):
res = es.search(index="gutenberg", size=20, body={"query": {"multi_match" : { "query": search_term, "fields": ["title", "content"] }}})
return render_template('results.html', res=res, term=search_term)
try:
res = es.search(index="gutenberg", size=20, body={"query": {"multi_match" : { "query": search_term, "fields": ["title", "content"] }}})
return render_template('results.html', res=res, term=search_term)
except:
return render_template('health.html', res="ERROR: Can't find any ElasticSearch servers.")

@app.route('/health')
def health():
Expand Down

0 comments on commit 06258b5

Please sign in to comment.