From 17c833a616ba27bd99e352512c013a14bdf47f5e Mon Sep 17 00:00:00 2001 From: sqozz Date: Thu, 28 Dec 2017 04:19:04 +0100 Subject: [PATCH] Add search --- indexer.py | 10 +++++++++- static/css/result.css | 4 ++++ templates/result.html | 20 +++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 static/css/result.css diff --git a/indexer.py b/indexer.py index 6165b79..1d38bb0 100644 --- a/indexer.py +++ b/indexer.py @@ -31,7 +31,15 @@ def create(): def search(): global strings print(strings) - return render_template("result.html", results=request.args.get("q", ""), strings=strings, language="english", categories=settings["categories"]) + connection = sqlite3.connect("torrentdb.sqlite") + c = connection.cursor() + term = request.args.get("q", "") + terms = term.split(" ") + terms = list(map(lambda x: "%" + x + "%", terms)) + search = " AND ".join(["name LIKE (?)"] * len(terms)) + c.execute("SELECT fileid, name FROM torrents WHERE " + search, terms) + results = c.fetchall() + return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"]) def init(): global strings diff --git a/static/css/result.css b/static/css/result.css new file mode 100644 index 0000000..8cb4b41 --- /dev/null +++ b/static/css/result.css @@ -0,0 +1,4 @@ +table, th, td { + width: 100%; + border: 1px solid white; +} diff --git a/templates/result.html b/templates/result.html index dbccc72..4187527 100644 --- a/templates/result.html +++ b/templates/result.html @@ -5,5 +5,23 @@ vim: ts=2 noexpandtab {% block title %}{{ super() }} - Results{% endblock%} {% set active_page = "search" %} {% block content %} -

{{results}}

+ + + + + + + + + + + {% for result in results %} + + + + + + {% endfor %} + +
NameSizeSnatchesULDL
{{ result[1] }}testN/AN/AN/A
{% endblock content%}