0.0.1s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from tinydb import TinyDB, Query
|
||||
import os
|
||||
import json
|
||||
from collections import Counter
|
||||
|
||||
class DB:
|
||||
def __init__(self):
|
||||
@@ -22,6 +23,7 @@ class DB:
|
||||
return self.db.all()
|
||||
|
||||
def get_search(self, ratings, tags):
|
||||
ratings
|
||||
results = self.db.search(
|
||||
self.File.rating.one_of(self.ratings) &
|
||||
self.File.tags.any(self.tags)
|
||||
@@ -32,5 +34,21 @@ class DB:
|
||||
results = self.db.search(self.File.tags == [])
|
||||
return results
|
||||
|
||||
def get_autocomplete(self, tag_slise):
|
||||
counter = Counter()
|
||||
for record in self.db.all():
|
||||
counter.update(record.get("tags", []))
|
||||
results = [
|
||||
{
|
||||
"tag": tag,
|
||||
"count": count
|
||||
}
|
||||
for tag, count in counter.items()
|
||||
if tag.lower().startswith(prefix)
|
||||
]
|
||||
results.sort(key=lambda x: x["count"], reverse=True)
|
||||
top_10 = results[:10]
|
||||
return top_10
|
||||
|
||||
def edit_data(self, id_file, edit_data):
|
||||
self.db.update(self.edit_data, self.File.md5 == self.id_file)
|
||||
Reference in New Issue
Block a user