mirror of
https://github.com/simon987/od-database.git
synced 2025-12-13 14:59:02 +00:00
Added website url & date in search results & fixed threading problem
This commit is contained in:
25
database.py
25
database.py
@@ -191,6 +191,31 @@ class Database:
|
||||
cursor.execute("DELETE FROM ApiToken WHERE token=?", (token, ))
|
||||
conn.commit()
|
||||
|
||||
def _get_websites(self) -> dict:
|
||||
|
||||
# todo: mem cache that
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT id, url FROM Website")
|
||||
|
||||
result = {}
|
||||
|
||||
for db_website in cursor.fetchall():
|
||||
result[db_website[0]] = db_website[1]
|
||||
return result
|
||||
|
||||
def join_search_result(self, page: dict) -> dict:
|
||||
|
||||
websites = self._get_websites()
|
||||
|
||||
for hit in page["hits"]["hits"]:
|
||||
hit["_source"]["website_url"] = websites[hit["_source"]["website_id"]]
|
||||
|
||||
return page
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user