Simple full text search.
This commit is contained in:
parent
f4632654b3
commit
b68b1e4e06
3 changed files with 19 additions and 9 deletions
17
app/agora.py
17
app/agora.py
|
@ -15,8 +15,9 @@
|
||||||
import datetime
|
import datetime
|
||||||
from flask import Blueprint, url_for, render_template, current_app, Response, redirect
|
from flask import Blueprint, url_for, render_template, current_app, Response, redirect
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from . import db
|
|
||||||
from . import config
|
from . import config
|
||||||
|
from . import db
|
||||||
|
from . import forms
|
||||||
bp = Blueprint('agora', __name__)
|
bp = Blueprint('agora', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,9 +72,17 @@ def wikilink(node):
|
||||||
def subnode(subnode):
|
def subnode(subnode):
|
||||||
return render_template('subnode_rendered.html', subnode=db.subnode_by_uri(subnode), backlinks=db.subnodes_by_outlink(subnode))
|
return render_template('subnode_rendered.html', subnode=db.subnode_by_uri(subnode), backlinks=db.subnodes_by_outlink(subnode))
|
||||||
|
|
||||||
@bp.route('/search/<query>')
|
# Searching with GET: potentially useful but probably not a good idea.
|
||||||
def search(query):
|
# @bp.route('/search/<query>')
|
||||||
return render_template('subnodes.html', subnodes=db.search_subnodes(query))
|
# def search(query):
|
||||||
|
# return render_template('subnodes.html', subnodes=db.search_subnodes(query))
|
||||||
|
|
||||||
|
@bp.route('/search', methods=('GET', 'POST'))
|
||||||
|
def search():
|
||||||
|
form = forms.SearchForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
return render_template('search.html', form=form, subnodes=db.search_subnodes(form.query.data))
|
||||||
|
return render_template('search.html', form=form)
|
||||||
|
|
||||||
@bp.route('/asset/<user>/<asset>')
|
@bp.route('/asset/<user>/<asset>')
|
||||||
def asset(user, asset):
|
def asset(user, asset):
|
||||||
|
|
|
@ -174,7 +174,7 @@ def subnodes_by_wikilink(wikilink, fuzzy_matching=True):
|
||||||
return subnodes
|
return subnodes
|
||||||
|
|
||||||
def search_subnodes(query):
|
def search_subnodes(query):
|
||||||
subnodes = [subnode for subnode in all_subnodes() if re.search(query, subnode.content)]
|
subnodes = [subnode for subnode in all_subnodes() if re.search(query, subnode.content, re.IGNORECASE)]
|
||||||
return subnodes
|
return subnodes
|
||||||
|
|
||||||
def subnodes_by_user(user):
|
def subnodes_by_user(user):
|
||||||
|
|
|
@ -30,10 +30,11 @@
|
||||||
<a href="/"><img src="/static/img/agora.png" class="logo" style="vertical-align: top" width="19" height="19"></a> |
|
<a href="/"><img src="/static/img/agora.png" class="logo" style="vertical-align: top" width="19" height="19"></a> |
|
||||||
</span>
|
</span>
|
||||||
<span align=left>
|
<span align=left>
|
||||||
<a href="/nodes">/nodes</a>
|
<a href="/nodes">nodes</a>
|
||||||
| <a href="/subnodes">/subnodes</a>
|
| <a href="/subnodes">subnodes</a>
|
||||||
| <a href="/journals">/journals</a>
|
| <a href="/journals">journals</a>
|
||||||
| <a href="/users">/users</a>
|
| <a href="/users">users</a>
|
||||||
|
| <a href="/search">search</a>
|
||||||
</span>
|
</span>
|
||||||
<span style="vertical-align: bottom; float:right">
|
<span style="vertical-align: bottom; float:right">
|
||||||
<a href="#" class="theme-toggle">theme</a>
|
<a href="#" class="theme-toggle">theme</a>
|
||||||
|
|
Loading…
Reference in a new issue