search module, wip

This commit is contained in:
scragg 2014-11-10 10:54:46 -06:00
parent c2404760b8
commit 312c61ef61
11 changed files with 59 additions and 5 deletions

View file

View file

@ -0,0 +1,15 @@
from realms.modules.wiki.models import Wiki
from realms.modules.search.models import Search
@Wiki.after('write_page')
def wiki_write_page(name, content, **kwargs):
body = dict(name=name,
content=content)
body.update(kwargs)
return Search.index('wiki', 'page', body=body)
@Wiki.after('rename_page')
def wiki_rename_page(*args, **kwargs):
pass

View file

@ -0,0 +1,17 @@
from realms import elastic
from realms.lib.model import HookMixin
class Search(HookMixin):
@classmethod
def index(cls, index, doc_type, id_=None, body=None):
return elastic.index(index=index, doc_type=doc_type, id=id_, body=body)
@classmethod
def wiki(cls, query):
return elastic.search(index='wiki', body={"query": {"match_all": {}}})
@classmethod
def users(cls, query):
pass

View file

@ -0,0 +1,10 @@
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from .models import Search
blueprint = Blueprint('search', __name__)
@blueprint.route('/_search')
def search():
results = Search.wiki(request.args.get('q'))
print results
return render_template('search/search.html', results=results)