Skip to content
Snippets Groups Projects
myapp.py 875 B
Newer Older
from whoosh.fields import *
import indexing

# Retrieving data
from whoosh.qparser import QueryParser

from flask import Flask, request, render_template
def search_index(keyword: str):
    ix = indexing.get_index()
    with ix.searcher() as searcher:
        # find entries with the words 'first' AND 'last'
        query = QueryParser("content", ix.schema).parse(keyword)
        results = searcher.search(query)
        # print all results
        result_links = []
        for r in results:
            result_links.append(r.fields()["url"])
        return result_links

search_index("platypus")

app = Flask(__name__)

@app.route("/")
def start():
    return render_template("start.html", title="start")

@app.route("/result")
def reverse():
    rev = request.args.get('rev')
    return render_template("result.html", title="search for: "+rev, result=search_index(rev))