add subject searching

master
eric 2021-04-17 18:33:14 -04:00
parent 8712445cea
commit ec7fe33f44
1 changed files with 9 additions and 2 deletions

View File

@ -26,7 +26,7 @@ import routes
from sqlalchemy import or_, and_
from libgutenberg.Models import (
Alias, Attribute, Author, Book, BookAuthor, Category, File, Lang, Locc)
Alias, Attribute, Author, Book, BookAuthor, Category, File, Lang, Locc, Subject)
import BaseSearcher
from errors import ErrorPage
@ -130,7 +130,7 @@ class AdvSearchPage(Page):
resultpks = None
searchterms = []
for key in terms:
if key in ['author', 'title']:
if key in ['author', 'title', 'subject']:
for word in params[key].split():
searchterms.append((key, word))
else:
@ -178,6 +178,13 @@ class AdvSearchPage(Page):
)).all()
key = 'Title'
elif key == 'subject':
word = "%{}%".format(val)
pks = query.join(Book.subjects).filter(
Subject.subject.ilike(word),
).all()
key = 'Subject'
pks = {row[0] for row in pks}
resultpks = resultpks.intersection(pks) if resultpks is not None else pks
num_rows = len(pks)