Fix #877
This commit is contained in:
parent
4552208c02
commit
55bdd13fb1
32
cps/web.py
32
cps/web.py
|
@ -78,6 +78,7 @@ import server
|
||||||
from reverseproxy import ReverseProxied
|
from reverseproxy import ReverseProxied
|
||||||
from updater import updater_thread
|
from updater import updater_thread
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import unidecode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from googleapiclient.errors import HttpError
|
from googleapiclient.errors import HttpError
|
||||||
|
@ -665,16 +666,23 @@ def get_search_results(term):
|
||||||
q = list()
|
q = list()
|
||||||
authorterms = re.split("[, ]+", term)
|
authorterms = re.split("[, ]+", term)
|
||||||
for authorterm in authorterms:
|
for authorterm in authorterms:
|
||||||
q.append(db.Books.authors.any(db.Authors.name.ilike("%" + authorterm + "%")))
|
q.append(db.Books.authors.any(db.or_(db.Authors.name.ilike("%" + authorterm + "%"),
|
||||||
|
db.Authors.name.ilike("%" + unidecode.unidecode(authorterm) + "%"))))
|
||||||
db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
|
db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
|
||||||
db.Books.authors.any(db.Authors.name.ilike("%" + term + "%"))
|
db.Books.authors.any(db.or_(db.Authors.name.ilike("%" + term + "%"),
|
||||||
|
db.Authors.name.ilike("%" + unidecode.unidecode(term) + "%")))
|
||||||
|
|
||||||
return db.session.query(db.Books).filter(common_filters()).filter(
|
return db.session.query(db.Books).filter(common_filters()).filter(
|
||||||
db.or_(db.Books.tags.any(db.Tags.name.ilike("%" + term + "%")),
|
db.or_(db.Books.tags.any(db.Tags.name.ilike("%" + term + "%")),
|
||||||
db.Books.series.any(db.Series.name.ilike("%" + term + "%")),
|
db.Books.series.any(db.Series.name.ilike("%" + term + "%")),
|
||||||
db.Books.authors.any(and_(*q)),
|
db.Books.authors.any(and_(*q)),
|
||||||
db.Books.publishers.any(db.Publishers.name.ilike("%" + term + "%")),
|
db.Books.publishers.any(db.Publishers.name.ilike("%" + term + "%")),
|
||||||
db.Books.title.ilike("%" + term + "%"))).all()
|
db.Books.title.ilike("%" + term + "%"),
|
||||||
|
db.Books.tags.any(db.Tags.name.ilike("%" + unidecode.unidecode(term) + "%")),
|
||||||
|
db.Books.series.any(db.Series.name.ilike("%" + unidecode.unidecode(term) + "%")),
|
||||||
|
db.Books.publishers.any(db.Publishers.name.ilike("%" + unidecode.unidecode(term) + "%")),
|
||||||
|
db.Books.title.ilike("%" + unidecode.unidecode(term) + "%")
|
||||||
|
)).all()
|
||||||
|
|
||||||
|
|
||||||
def feed_search(term):
|
def feed_search(term):
|
||||||
|
@ -1969,15 +1977,20 @@ def advanced_search():
|
||||||
searchterm = " + ".join(filter(None, searchterm))
|
searchterm = " + ".join(filter(None, searchterm))
|
||||||
q = q.filter()
|
q = q.filter()
|
||||||
if author_name:
|
if author_name:
|
||||||
q = q.filter(db.Books.authors.any(db.Authors.name.ilike("%" + author_name + "%")))
|
q = q.filter(db.Books.authors.any(db.or_(db.Authors.name.ilike("%" + author_name + "%"),
|
||||||
|
db.Authors.name.ilike("%" + unidecode.unidecode(author_name)
|
||||||
|
+ "%"))))
|
||||||
if book_title:
|
if book_title:
|
||||||
q = q.filter(db.Books.title.ilike("%" + book_title + "%"))
|
q = q.filter(db.or_(db.Books.title.ilike("%" + book_title + "%"),
|
||||||
|
db.Books.title.ilike("%" + unidecode.unidecode(book_title) + "%")))
|
||||||
if pub_start:
|
if pub_start:
|
||||||
q = q.filter(db.Books.pubdate >= pub_start)
|
q = q.filter(db.Books.pubdate >= pub_start)
|
||||||
if pub_end:
|
if pub_end:
|
||||||
q = q.filter(db.Books.pubdate <= pub_end)
|
q = q.filter(db.Books.pubdate <= pub_end)
|
||||||
if publisher:
|
if publisher:
|
||||||
q = q.filter(db.Books.publishers.any(db.Publishers.name.ilike("%" + publisher + "%")))
|
q = q.filter(db.Books.publishers.any(db.or_(db.Publishers.name.ilike("%" + publisher + "%"),
|
||||||
|
db.Publishers.name.ilike("%" + unidecode.unidecode(publisher)
|
||||||
|
+ "%"),)))
|
||||||
for tag in include_tag_inputs:
|
for tag in include_tag_inputs:
|
||||||
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
|
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
|
||||||
for tag in exclude_tag_inputs:
|
for tag in exclude_tag_inputs:
|
||||||
|
@ -2000,7 +2013,9 @@ def advanced_search():
|
||||||
rating_low = int(rating_low) *2
|
rating_low = int(rating_low) *2
|
||||||
q = q.filter(db.Books.ratings.any(db.Ratings.rating >= rating_low))
|
q = q.filter(db.Books.ratings.any(db.Ratings.rating >= rating_low))
|
||||||
if description:
|
if description:
|
||||||
q = q.filter(db.Books.comments.any(db.Comments.text.ilike("%" + description + "%")))
|
q = q.filter(db.Books.comments.any(db.or_(db.Comments.text.ilike("%" + description + "%"),
|
||||||
|
db.Comments.text.ilike("%" + unidecode.unidecode(description)
|
||||||
|
+ "%"))))
|
||||||
|
|
||||||
# search custom culumns
|
# search custom culumns
|
||||||
for c in cc:
|
for c in cc:
|
||||||
|
@ -2015,7 +2030,8 @@ def advanced_search():
|
||||||
db.cc_classes[c.id].value == custom_query ))
|
db.cc_classes[c.id].value == custom_query ))
|
||||||
else:
|
else:
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
||||||
db.cc_classes[c.id].value.ilike("%" + custom_query + "%")))
|
db.or_(db.cc_classes[c.id].value.ilike("%" + custom_query + "%"),
|
||||||
|
db.cc_classes[c.id].value.ilike("%" + unidecode.unidecode(custom_query) + "%"))))
|
||||||
q = q.all()
|
q = q.all()
|
||||||
ids = list()
|
ids = list()
|
||||||
for element in q:
|
for element in q:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user