From ec7fe33f44a60d54bfb7e9e0b10d671bbfb44077 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 17 Apr 2021 18:33:14 -0400 Subject: [PATCH] add subject searching --- AdvSearchPage.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AdvSearchPage.py b/AdvSearchPage.py index 5949750..4a9d76d 100644 --- a/AdvSearchPage.py +++ b/AdvSearchPage.py @@ -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)