Skip to content
Snippets Groups Projects
Commit 1310e543 authored by felixwelter's avatar felixwelter
Browse files

Fix return value when no slide is found

parent 1a72f896
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ import glob
import os
from pathlib import Path
import pandas as pd
from flask import Flask, render_template, request, redirect, send_file, jsonify, flash
from werkzeug.utils import secure_filename
......@@ -55,22 +54,21 @@ def upload():
@app.route("/search", methods=['POST'])
def query():
try:
index = Index(index_dir=INDEX_DIR)
query = request.form.get("term")
context = request.form.get("context")
amount = int(request.form.get("amount"))
results = index.search(query, context)[:amount]
if len(results) == 0:
return jsonify({
"type": "miss"
})
full_path = lambda res: os.getenv('EXTERNAL_HOST', '<PLEASE_SET_EXTERNAL_HOST_ENV_VAR>') + \
"/slide/" + res["file_name"] + "_" + str(res["page"]) + ".jpg"
return jsonify({
"type": "image",
"paths": [{"path": full_path(res), "url": full_path(res)} for res in results]
})
except IndexError:
return jsonify({
"type": "miss"
})
@app.route("/reset_index", methods=['POST'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment