2014-11-13 01:06:56 +02:00
|
|
|
import click
|
2016-07-11 00:47:43 +03:00
|
|
|
from flask import current_app
|
|
|
|
from realms import search, cli_group
|
2014-11-13 01:06:56 +02:00
|
|
|
from realms.modules.wiki.models import Wiki
|
|
|
|
|
|
|
|
|
2016-07-11 00:47:43 +03:00
|
|
|
@cli_group(short_help="Search Module")
|
2014-11-13 01:06:56 +02:00
|
|
|
def cli():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
def rebuild_index():
|
|
|
|
""" Rebuild search index
|
|
|
|
"""
|
2016-07-11 00:47:43 +03:00
|
|
|
if current_app.config.get('SEARCH_TYPE') == 'simple':
|
2014-11-13 01:06:56 +02:00
|
|
|
click.echo("Search type is simple, try using elasticsearch.")
|
|
|
|
return
|
|
|
|
|
2016-07-11 00:47:43 +03:00
|
|
|
# Wiki
|
|
|
|
search.delete_index('wiki')
|
|
|
|
wiki = Wiki(current_app.config['WIKI_PATH'])
|
|
|
|
for entry in wiki.get_index():
|
|
|
|
page = wiki.get_page(entry['name'])
|
|
|
|
if not page:
|
|
|
|
# Some non-markdown files may have issues
|
|
|
|
continue
|
|
|
|
# TODO add email?
|
2016-07-14 03:48:28 +03:00
|
|
|
# TODO I have concens about indexing the commit info from latest revision, see #148
|
|
|
|
info = next(page.history)
|
2016-07-11 00:47:43 +03:00
|
|
|
body = dict(name=page.name,
|
|
|
|
content=page.data,
|
2016-07-14 03:48:28 +03:00
|
|
|
message=info['message'],
|
|
|
|
username=info['author'],
|
2016-07-11 00:47:43 +03:00
|
|
|
updated_on=entry['mtime'],
|
|
|
|
created_on=entry['ctime'])
|
2016-07-12 07:27:39 +03:00
|
|
|
search.index_wiki(page.name, body)
|