realms-wiki/realms/modules/search/models.py

26 lines
645 B
Python
Raw Normal View History

2014-11-10 18:54:46 +02:00
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):
2014-11-12 01:06:28 +02:00
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']]
2014-11-10 18:54:46 +02:00
@classmethod
def users(cls, query):
pass