diff --git a/indexer.py b/indexer.py index 1d38bb0..2d17a21 100644 --- a/indexer.py +++ b/indexer.py @@ -33,11 +33,29 @@ def search(): print(strings) 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) + + search_params = [] + search = "" + fields = list(request.args.keys()) + for field in fields: + query_list = request.args.getlist(field) + for query in query_list: + if len(search) > 0: + search += " AND " + + if field is "q": + names = query.split(" ") + search_params += list(map(lambda x: "%" + x + "%", names)) + search += " AND ".join(["name LIKE (?)"] * len(query.split(" "))) + elif field is "c": + search_params += query.split(" ") + search += " AND ".join(["category LIKE (?)"] * len(query.split(" "))) + elif field is "s": + search_params += query.split(" ") + search += " AND ".join(["subcategory LIKE (?)"] * len(query.split(" "))) + + print(search) + c.execute("SELECT fileid, name FROM torrents WHERE " + search, search_params) results = c.fetchall() return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"]) diff --git a/static/css/search.css b/static/css/search.css index befb597..0c4505c 100644 --- a/static/css/search.css +++ b/static/css/search.css @@ -8,3 +8,13 @@ margin-left: auto; margin-right: auto; } + +.search_container { + display: flex; + flex-direction: column; + align-items: center; +} + +.search_container form { + width: 80%; +} diff --git a/templates/categories.html b/templates/categories.html index 5f40995..951f1fa 100644 --- a/templates/categories.html +++ b/templates/categories.html @@ -9,11 +9,11 @@ vim: ts=2 noexpandtab