Add multi-purpose search
This commit is contained in:
parent
17c833a616
commit
77e11c3edc
4 changed files with 37 additions and 9 deletions
28
indexer.py
28
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"])
|
||||
|
||||
|
|
|
@ -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%;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ vim: ts=2 noexpandtab
|
|||
<ul>
|
||||
{% for category in categories %}
|
||||
<li>
|
||||
{{ category }}
|
||||
<a href="search?c={{ category }}">{{ category }}</a>
|
||||
<ul>
|
||||
{% for sub_category in categories[category] %}
|
||||
<li>
|
||||
{{ sub_category }}
|
||||
<a href="search?s={{ sub_category }}">{{ sub_category }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -14,14 +14,14 @@ vim: ts=2 noexpandtab
|
|||
<th>UL</th>
|
||||
<th>DL</th>
|
||||
</tr>
|
||||
{% for result in results %}
|
||||
<tr>
|
||||
{% for result in results %}
|
||||
<td>{{ result[1] }}</td>
|
||||
<td>test</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock content%}
|
||||
|
|
Loading…
Reference in a new issue