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)
|
print(strings)
|
||||||
connection = sqlite3.connect("torrentdb.sqlite")
|
connection = sqlite3.connect("torrentdb.sqlite")
|
||||||
c = connection.cursor()
|
c = connection.cursor()
|
||||||
term = request.args.get("q", "")
|
|
||||||
terms = term.split(" ")
|
search_params = []
|
||||||
terms = list(map(lambda x: "%" + x + "%", terms))
|
search = ""
|
||||||
search = " AND ".join(["name LIKE (?)"] * len(terms))
|
fields = list(request.args.keys())
|
||||||
c.execute("SELECT fileid, name FROM torrents WHERE " + search, terms)
|
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()
|
results = c.fetchall()
|
||||||
return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"])
|
return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"])
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,13 @@
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: 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>
|
<ul>
|
||||||
{% for category in categories %}
|
{% for category in categories %}
|
||||||
<li>
|
<li>
|
||||||
{{ category }}
|
<a href="search?c={{ category }}">{{ category }}</a>
|
||||||
<ul>
|
<ul>
|
||||||
{% for sub_category in categories[category] %}
|
{% for sub_category in categories[category] %}
|
||||||
<li>
|
<li>
|
||||||
{{ sub_category }}
|
<a href="search?s={{ sub_category }}">{{ sub_category }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -14,14 +14,14 @@ vim: ts=2 noexpandtab
|
||||||
<th>UL</th>
|
<th>UL</th>
|
||||||
<th>DL</th>
|
<th>DL</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
|
<tr>
|
||||||
<td>{{ result[1] }}</td>
|
<td>{{ result[1] }}</td>
|
||||||
<td>test</td>
|
<td>test</td>
|
||||||
<td>N/A</td>
|
<td>N/A</td>
|
||||||
<td>N/A</td>
|
<td>N/A</td>
|
||||||
<td>N/A</td>
|
<td>N/A</td>
|
||||||
{% endfor %}
|
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% endblock content%}
|
{% endblock content%}
|
||||||
|
|
Loading…
Reference in a new issue