Simple full text search.

This commit is contained in:
Flancian 2020-11-16 16:39:30 +01:00
parent f4632654b3
commit b68b1e4e06
3 changed files with 19 additions and 9 deletions

View file

@ -15,8 +15,9 @@
import datetime
from flask import Blueprint, url_for, render_template, current_app, Response, redirect
from markupsafe import escape
from . import db
from . import config
from . import db
from . import forms
bp = Blueprint('agora', __name__)
@ -71,9 +72,17 @@ def wikilink(node):
def subnode(subnode):
return render_template('subnode_rendered.html', subnode=db.subnode_by_uri(subnode), backlinks=db.subnodes_by_outlink(subnode))
@bp.route('/search/<query>')
def search(query):
return render_template('subnodes.html', subnodes=db.search_subnodes(query))
# Searching with GET: potentially useful but probably not a good idea.
# @bp.route('/search/<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>')
def asset(user, asset):

View file

@ -174,7 +174,7 @@ def subnodes_by_wikilink(wikilink, fuzzy_matching=True):
return subnodes
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
def subnodes_by_user(user):

View file

@ -30,10 +30,11 @@
<a href="/"><img src="/static/img/agora.png" class="logo" style="vertical-align: top" width="19" height="19"></a> |
</span>
<span align=left>
<a href="/nodes">/nodes</a>
| <a href="/subnodes">/subnodes</a>
| <a href="/journals">/journals</a>
| <a href="/users">/users</a>
<a href="/nodes">nodes</a>
| <a href="/subnodes">subnodes</a>
| <a href="/journals">journals</a>
| <a href="/users">users</a>
| <a href="/search">search</a>
</span>
<span style="vertical-align: bottom; float:right">
<a href="#" class="theme-toggle">theme</a>