|
|
|
@ -335,7 +335,6 @@ def edit_stack_by_id(id):
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('show_stack_by_id', id=id))
|
|
|
|
|
return render_template('edit_stack_detail.html', stack=stack, form=form)
|
|
|
|
|
## search
|
|
|
|
|
|
|
|
|
|
## search
|
|
|
|
|
|
|
|
|
@ -352,18 +351,28 @@ def show_books():
|
|
|
|
|
def search_results(searchtype, query):
|
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
|
random_order=Book.query.order_by(func.random()).limit(10)
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Title':
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query)).all()
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
|
|
|
|
|
|
if searchtype == 'Category':
|
|
|
|
|
results=Book.query.filter(Book.category.contains(query)).all()
|
|
|
|
|
results=Book.query.filter(Book.category.contains(query))
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Author':
|
|
|
|
|
results=db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query))
|
|
|
|
|
|
|
|
|
|
if searchtype== 'Stack':
|
|
|
|
|
results=db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query))
|
|
|
|
|
|
|
|
|
|
if searchtype== 'All':
|
|
|
|
|
results=Book.query.whoosh_search(query).all()
|
|
|
|
|
# results=Book.query.whoosh_search(query)
|
|
|
|
|
results=Book.query.filter(Book.title.contains(query))
|
|
|
|
|
results=results.union(Book.query.filter(Book.category.contains(query)))
|
|
|
|
|
results=results.union(db.session.query(Book).join(Book.authors).filter(Author.author_name.contains(query)))
|
|
|
|
|
results=results.union(db.session.query(Book).join(Book.stacks).filter(Stack.stack_name.contains(query)))
|
|
|
|
|
|
|
|
|
|
if not results:
|
|
|
|
|
if results.count() == 0:
|
|
|
|
|
upload_form = UploadForm(title= query, author='')
|
|
|
|
|
return render_template('red_link.html', form=upload_form, title=query)
|
|
|
|
|
|
|
|
|
@ -372,7 +381,11 @@ def search_results(searchtype, query):
|
|
|
|
|
results = []
|
|
|
|
|
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
|
|
|
|
|
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query)
|
|
|
|
|
count = results.count()
|
|
|
|
|
whole = Book.query.count()
|
|
|
|
|
percentage = float(count / whole * 100)
|
|
|
|
|
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Search - autocomplete
|
|
|
|
|
autocomplete_suggestions = []
|
|
|
|
|