1
0
Fork 0
mirror of https://github.com/Findus23/cr-search.git synced 2024-09-19 15:23:44 +02:00

fix and add colors and optimize server SQL

This commit is contained in:
Lukas Winkler 2020-04-17 18:00:42 +02:00
parent a69cc8dc57
commit 85f95deef1
Signed by: lukas
GPG key ID: 54DE4D798D244853
3 changed files with 26 additions and 6 deletions

View file

@ -1,10 +1,15 @@
from data import colors_c2
from data import colors_c2, colors_c1
from models import Person, Series
campaign2 = Series.select().where(Series.title == "Campaign 2").get()
campaign1 = Series.select().where(Series.title == "Campaign 1").get()
p: Person
for p in Person.select():
campaign2 = Series.select().where(Series.title == "Campaign 2")
print(p)
if p.name in colors_c1.keys() and p.series == campaign1:
print(p.name)
p.color = colors_c1[p.name]
p.save()
if p.name in colors_c2.keys() and p.series == campaign2:
print(p.name)
p.color = colors_c2[p.name]

14
data.py
View file

@ -1,3 +1,14 @@
colors_c1 = {
"Travis": "#7592a4",
"Marisha": "#bd6b1e",
"Taliesin": "#3c487d",
"Ashley": "#fdd9be",
"Sam": "#781485",
"Liam": "#3d7580",
"Laura": "#28607d",
"Orion": "#933326"
}
colors_c2 = {
"Laura": "#59c3f9",
"Marisha": "#00146e",
@ -6,7 +17,8 @@ colors_c2 = {
"Ashley": "#868984",
"Sam": "#dae1dd",
"Travis": "#076708",
"Matt": "#471f0e" # random color
"Matt": "#005d73", # random color
"Khary": "#bcc9e3"
}
single_speaker = {

View file

@ -51,13 +51,16 @@ def search():
a = Alias(fn.ts_rank(Line.search_text, fn.plainto_tsquery('english', query)), "rank")
results = Line.select(Line, Person, Episode, a).where(
results = Line.select(Line, Person, Episode, Series, a).where(
(Line.search_text.match(query, language="english", plain=True))
&
(Episode.episode_number <= until)
&
(Episode.series == series)
).order_by(SQL("rank DESC")).join(Person).switch(Line).join(Episode).limit(20)
).order_by(SQL("rank DESC")) \
.join(Person).switch(Line) \
.join(Episode).join(Series) \
.limit(20)
if len(results) == 0:
result: cursor = db.execute_sql("select plainto_tsquery('english',%s)", [query])