Add search
This commit is contained in:
		
							
								
								
									
										10
									
								
								indexer.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								indexer.py
									
									
									
									
									
								
							@@ -31,7 +31,15 @@ def create():
 | 
				
			|||||||
def search():
 | 
					def search():
 | 
				
			||||||
	global strings
 | 
						global strings
 | 
				
			||||||
	print(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():
 | 
					def init():
 | 
				
			||||||
	global strings
 | 
						global strings
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								static/css/result.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								static/css/result.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					table, th, td {
 | 
				
			||||||
 | 
						width: 100%;
 | 
				
			||||||
 | 
						border: 1px solid white;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -5,5 +5,23 @@ vim: ts=2 noexpandtab
 | 
				
			|||||||
{% block title %}{{ super() }} - Results{% endblock%}
 | 
					{% block title %}{{ super() }} - Results{% endblock%}
 | 
				
			||||||
{% set active_page = "search" %}
 | 
					{% set active_page = "search" %}
 | 
				
			||||||
{% block content %}
 | 
					{% block content %}
 | 
				
			||||||
<p>{{results}}</p>
 | 
					<link href="{{ url_for("static", filename="css/result.css") }}" rel="stylesheet">
 | 
				
			||||||
 | 
						<table>
 | 
				
			||||||
 | 
							<tr>
 | 
				
			||||||
 | 
								<th>Name</th>
 | 
				
			||||||
 | 
								<th>Size</th>
 | 
				
			||||||
 | 
								<th>Snatches</th>
 | 
				
			||||||
 | 
								<th>UL</th>
 | 
				
			||||||
 | 
								<th>DL</th>
 | 
				
			||||||
 | 
							</tr>
 | 
				
			||||||
 | 
							<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>
 | 
				
			||||||
 | 
						</table>
 | 
				
			||||||
{% endblock content%}
 | 
					{% endblock content%}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user