search pass two
This commit is contained in:
parent
312c61ef61
commit
13d4be8937
7 changed files with 63 additions and 11 deletions
|
@ -3,11 +3,13 @@ from realms.modules.search.models import Search
|
|||
|
||||
|
||||
@Wiki.after('write_page')
|
||||
def wiki_write_page(name, content, **kwargs):
|
||||
def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs):
|
||||
body = dict(name=name,
|
||||
content=content)
|
||||
body.update(kwargs)
|
||||
return Search.index('wiki', 'page', body=body)
|
||||
content=content,
|
||||
message=message,
|
||||
email=email,
|
||||
username=username)
|
||||
return Search.index('wiki', 'page', id_=name, body=body)
|
||||
|
||||
|
||||
@Wiki.after('rename_page')
|
||||
|
|
|
@ -10,7 +10,16 @@ class Search(HookMixin):
|
|||
|
||||
@classmethod
|
||||
def wiki(cls, query):
|
||||
return elastic.search(index='wiki', body={"query": {"match_all": {}}})
|
||||
if not query:
|
||||
return []
|
||||
|
||||
res = elastic.search(index='wiki', body={"query": {
|
||||
"multi_match": {
|
||||
"query": query,
|
||||
"fields": ["name^3", "content"]
|
||||
}}})
|
||||
|
||||
return [hit["_source"] for hit in res['hits']['hits']]
|
||||
|
||||
@classmethod
|
||||
def users(cls, query):
|
||||
|
|
|
@ -1,10 +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