Skip to content
Snippets Groups Projects
Commit 5b4a2a55 authored by felixwelter's avatar felixwelter
Browse files

Switch to new request format

parent 20a6127d
No related branches found
No related tags found
No related merge requests found
from flask import Flask, render_template, request, redirect, send_file
from flask import Flask, render_template, request, redirect, send_file, jsonify
from elasticsearch_dsl import connections, Search
import os
......@@ -7,39 +7,55 @@ app = Flask(__name__)
connections.create_connection(hosts=[os.getenv('ES_HOST', 'localhost')], timeout=20)
@app.route('/search')
@app.route('/test')
def test_page():
return render_template('index.html')
def make_text_response(text):
print(text[:100])
return jsonify({
"type": "text",
"text": text
})
@app.route('/search', methods=['POST'])
def index():
term = request.args.get('term')
term = request.form.get('term')
print(term)
s = Search(index="en_wiki") \
.query("match", title=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
return make_text_response(response[0].text)
s = Search(index="en_wiki") \
.query("match_phrase", title=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
return make_text_response(response[0].text)
s = Search(index="en_wiki") \
.query("match", text=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
return make_text_response(response[0].text)
s = Search(index="en_wiki") \
.query("match_phrase", text=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
return make_text_response(response[0].text)
return "No hits"
return jsonify({
"type": "miss"
})
if __name__ == '__main__':
......
<!DOCTYPE HTML>
<html>
<head>
<title>Slide index</title></head>
<body>
<h1>Query</h1>
<form action="search" method="post">
<input name="term" placeholder="term"><br>
<input name="context" placeholder="context"><br>
<input type="submit" value="Query">
</form>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment