search module, wip
This commit is contained in:
parent
c2404760b8
commit
312c61ef61
11 changed files with 59 additions and 5 deletions
0
realms/modules/search/__init__.py
Normal file
0
realms/modules/search/__init__.py
Normal file
15
realms/modules/search/hooks.py
Normal file
15
realms/modules/search/hooks.py
Normal 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
|
17
realms/modules/search/models.py
Normal file
17
realms/modules/search/models.py
Normal 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
|
10
realms/modules/search/views.py
Normal file
10
realms/modules/search/views.py
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue