diff --git a/app/__init__.py b/app/__init__.py index b2dc543..fecc4ff 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -8,7 +8,7 @@ import os import click from werkzeug.utils import secure_filename from sqlalchemy.dialects import registry -import flask_whooshalchemyplus +# import flask_whooshalchemyplus not using whoosh anymore registry.register("rqlite.pyrqlite", "sqlalchemy_rqlite.pyrqlite", "dialect") @@ -27,9 +27,6 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'rqlite+pyrqlite://localhost:4001/' app.config['DEBUG'] = True app.config['PORT'] = 80 -# set the location for the whoosh index -app.config['WHOOSH_BASE'] = 'whoosh' - #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'mydatabase.db') db = SQLAlchemy(app) @@ -39,5 +36,7 @@ socketio = SocketIO(app) app.config.from_object(__name__) from app import views -flask_whooshalchemyplus.init_app(app) # initialize +# set the location for the whoosh index +# app.config['WHOOSH_BASE'] = 'whoosh' +# flask_whooshalchemyplus.init_app(app) # initialize diff --git a/app/forms.py b/app/forms.py index e276a3d..0e5e25f 100755 --- a/app/forms.py +++ b/app/forms.py @@ -46,6 +46,9 @@ class EditStackForm(FlaskForm): class SearchForm(FlaskForm): choices = [('All', 'All'), ('Title', 'Title'), - ('Category', 'Category')] + ('Author', 'Author'), + ('Category', 'Category'), + ('Stack', 'Stack')] select = SelectField('', choices=choices) search = StringField('', validators=[InputRequired()]) + diff --git a/app/models.py b/app/models.py index d2361e5..80868ec 100755 --- a/app/models.py +++ b/app/models.py @@ -17,7 +17,6 @@ stacks = db.Table('books_stacks', class Book(db.Model): __tablename__ = 'books' - __searchable__ = ['title', 'category', 'fileformat'] # these fields will be indexed by whoosh id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(255)) diff --git a/app/static/css/style.css b/app/static/css/style.css index be7e00f..a39c5b2 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -1,15 +1,4 @@ @import url("../fonts/fonts_style.css"); -/* -Font-names: -junicoderegular -junicoderegularcondensed -junicodeitalic -junicodeitaliccondensed -junicodebold -junicodeboldcondensed -junicodebolditalic -junicodebolditaliccondensed -*/ *{ font-family: "Archivo Narrow"; @@ -121,7 +110,7 @@ cursor: pointer; .header input{ height:40px; width: 500px; -font-size: 30px; +font-size: 24px; font-weight: bold; } @@ -136,10 +125,10 @@ margin: 0; float: left; width: 320px; height: 36px; -font-size: 20px; +font-size: 18px; font-weight: regular; padding: 2px; -background:rgba(50, 50, 50, 0.2); +background:rgb(240, 240, 240); border:0px; box-shadow: inset 0 0 5px rgba(000,000,000, 0.2); } @@ -200,7 +189,7 @@ font-size: 12px; top:0; left:0; position: fixed; - font-size: 20px; + font-size: 18px; background-color: yellow; } diff --git a/app/templates/results.html b/app/templates/results.html index aa1acf7..1ee29ef 100644 --- a/app/templates/results.html +++ b/app/templates/results.html @@ -3,16 +3,21 @@ {% block main %}
+
{% from "_formhelpers.html" import render_field %}
{{ form.select(style="width: 100px; margin: 10px; float: left; font-size: 20px") }}
- +
- -
-

Search Results for: {{ query }}

+
+
+

Results: "{{ query }}" included in {{ count }} out of {{ whole }} items

+
+
+
+
{% with messages = get_flashed_messages() %} {% if messages %}
@@ -53,11 +58,11 @@
  • {{ stack.stack_name }}
  • {% endfor %} - - + ==> - {% endfor %} + {% endfor %} +
    @@ -92,11 +97,13 @@ {% for stack in book.stacks %}
  • {{ stack.stack_name }}
  • - {% endfor %} + {% endfor %} + - + ==> + {% endfor %}

    diff --git a/app/templates/show_books.html b/app/templates/show_books.html index 101ce54..5f8e7b9 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -7,7 +7,7 @@

    {{ form.select(style="width: 100px; margin: 10px; float: left; font-size: 20px") }}
    - +

    All Books

    @@ -60,7 +60,7 @@
  • {{ stack.stack_name }}
  • {% endfor %} - + ==> diff --git a/app/views.py b/app/views.py index 7d77122..58edf45 100755 --- a/app/views.py +++ b/app/views.py @@ -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 = []