mirror of
https://github.com/simon987/od-database.git
synced 2025-12-13 14:59:02 +00:00
Quick hack for search order options
This commit is contained in:
16
database.py
16
database.py
@@ -30,6 +30,13 @@ class File:
|
||||
|
||||
class Database:
|
||||
|
||||
SORT_ORDERS = {
|
||||
"score": "ORDER BY rank",
|
||||
"size_asc": "ORDER BY size ASC",
|
||||
"size_dsc": "ORDER BY size DESC",
|
||||
"none": ""
|
||||
}
|
||||
|
||||
def __init__(self, db_path):
|
||||
|
||||
self.db_path = db_path
|
||||
@@ -200,18 +207,21 @@ class Database:
|
||||
|
||||
return stats
|
||||
|
||||
def search(self, q, limit: int = 25, offset: int = 0):
|
||||
def search(self, q, limit: int = 25, offset: int = 0, sort_order="score"):
|
||||
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
order_by = Database.SORT_ORDERS.get(sort_order, "")
|
||||
print(order_by)
|
||||
cursor.execute("SELECT size, Website.url, WebsitePath.path, File.name, Website.id FROM File_index "
|
||||
"INNER JOIN File ON File.id = File_index.rowid "
|
||||
"INNER JOIN WebsitePath ON File.path_id = WebsitePath.id "
|
||||
"INNER JOIN Website ON website_id = Website.id "
|
||||
"WHERE File_index MATCH ? "
|
||||
"ORDER BY rank LIMIT ? OFFSET ?", (q, limit, offset * limit))
|
||||
"WHERE File_index MATCH ? " +
|
||||
order_by + " LIMIT ? OFFSET ?",
|
||||
(q, limit, offset * limit))
|
||||
except sqlite3.OperationalError as e:
|
||||
raise InvalidQueryException(str(e))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user