Skip to content
This repository was archived by the owner on May 20, 2018. It is now read-only.

Commit ed37966

Browse files
author
Lev Lazinskiy
committed
[feature] Full Text Search Implemented
1 parent 7649f79 commit ed37966

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

app/main/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ class ShareForm(Form):
1919
class NotebookForm(Form):
2020
title = StringField('Title:', validators=[Required()])
2121
submit = SubmitField('Submit')
22+
23+
class SearchForm(Form):
24+
search_field = StringField()
25+
submit = SubmitField('Search')

app/main/views.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ def notebook(id):
183183
abort(403)
184184
return render_template('app/notebook.html', notebook=notebook, notes=notebook._show_notes())
185185

186+
@main.route('/search')
187+
@login_required
188+
def search():
189+
form = SearchForm()
190+
if request.args.get('search_field', ''):
191+
query = request.args.get('search_field', '')
192+
results = Note.query.search(query).all()
193+
if len(results) == 0:
194+
flash('Hmm, we did not find any braindumps matching your search. Try again?')
195+
return render_template('app/search.html', form=form, notes=results)
196+
return render_template('app/search.html', form=form)
197+
186198

187199
@main.route('/shutdown')
188200
def server_shutdown():

app/templates/app/app_base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<li class="sidebar-item">
2222
<a href="/"><img class="app-logo" src="{{ url_for('static', filename='images/logo.png')}}"></img></a>
2323
</li>
24+
<li class="sidebar-item" data-toggle="tooltip" data-placement="right" title="Search">
25+
<a href="/search"><span class="nav-item glyphicon glyphicon-search" aria-hidden="true"></a></span>
26+
</li>
2427
<li class="sidebar-item" data-toggle="tooltip" data-placement="right" title="Add a Note">
2528
<a href="/add"><span class="nav-item glyphicon glyphicon-plus" aria-hidden="true"></a></span>
2629
</li>

app/templates/app/search.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends "app/app_base.html" %}
2+
{% import "bootstrap/wtf.html" as wtf %}
3+
{% import "_macros.html" as macros %}
4+
5+
{% block title %}BrainDump{% endblock %}
6+
7+
{% block page_content %}
8+
9+
<h1 class="top"> Search for Anything </h1>
10+
11+
<form class="form form-horizontal" action="/search" role="form">
12+
{{ wtf.form_field(form.search_field) }}
13+
{{ wtf.form_field(form.submit, class="btn btn-default form-group") }}
14+
</form>
15+
16+
{% include 'app/_notes.html' %}
17+
18+
19+
{% endblock %}
20+
21+
{% block scripts %}
22+
{{ super() }}
23+
<script src="{{ url_for('static', filename='js/libs/marked.js') }}"></script>
24+
{% endblock %}

0 commit comments

Comments
 (0)