-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
41 lines (31 loc) · 1.01 KB
/
Copy pathsearch.py
File metadata and controls
41 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, request, render_template
from whoosh import index
from whoosh.qparser import QueryParser
import numpy as np
# open woosh index
ix = index.open_dir("indexdir")
# Retrieving data
# flask --app search run
app = Flask(__name__)
# landing page
@app.route("/")
def start():
return render_template("start.html")
# search page
@app.route("/search")
def search():
# Instantiate hits
hits = [""]
# open the searcher
with ix.searcher() as searcher:
# find entries containing the query
print(type("q"))
query = QueryParser("body", ix.schema).parse(request.args["q"])
results = searcher.search(query)
# extract data from the individual results while iterating over them
for i in range(len(results)):
hits.append(
[results[i]["url"], [results[i]["title"]], [results[i]["excerpt"]]]
)
# Hand the extratcted data over to the template
return render_template("searched.html", rev=hits, len=len(results))