diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 5171ba3b..7a1aa472 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -4,10 +4,11 @@ import redis import ConfigParser import json -from flask import Flask, render_template, jsonify +from flask import Flask, render_template, jsonify, request import flask import os + # CONFIG # configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg') if not os.path.exists(configfile): @@ -58,6 +59,27 @@ def stuff(): return jsonify(row1=get_queues(r_serv)) +@app.route("/search", methods=['POST']) +def search(): + query = request.form['query'] + q = [] + q.append(query) + r = [] + # Search + from whoosh import index + from whoosh.fields import Schema, TEXT, ID + schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) + + indexpath = os.path.join(os.environ['AIL_HOME'], cfg.get("Indexer", "path")) + ix = index.open_dir(indexpath) + from whoosh.qparser import QueryParser + with ix.searcher() as searcher: + query = QueryParser("content", ix.schema).parse(" ".join(q)) + results = searcher.search(query, limit=None) + for x in results: + r.append(x.items()[0][1]) + return render_template("search.html", r=r) + @app.route("/") def index(): return render_template("index.html") diff --git a/var/www/templates/Queue_live_Monitoring.html b/var/www/templates/Queue_live_Monitoring.html index b8e5791e..81b322b3 100644 --- a/var/www/templates/Queue_live_Monitoring.html +++ b/var/www/templates/Queue_live_Monitoring.html @@ -40,4 +40,4 @@ $(document).ready(function () {