2014-11-13 01:06:56 +02:00
|
|
|
import click
|
2015-07-22 20:01:49 +03:00
|
|
|
from realms import create_app, search, flask_cli
|
2014-11-13 01:06:56 +02:00
|
|
|
from realms.modules.wiki.models import Wiki
|
|
|
|
from realms.lib.util import filename_to_cname
|
|
|
|
|
|
|
|
|
2015-07-22 20:01:49 +03:00
|
|
|
@flask_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
|
|
|
|
"""
|
|
|
|
app = create_app()
|
|
|
|
|
|
|
|
if app.config.get('SEARCH_TYPE') == 'simple':
|
|
|
|
click.echo("Search type is simple, try using elasticsearch.")
|
|
|
|
return
|
|
|
|
|
|
|
|
with app.app_context():
|
|
|
|
# Wiki
|
|
|
|
search.delete_index('wiki')
|
|
|
|
wiki = Wiki(app.config['WIKI_PATH'])
|
|
|
|
for entry in wiki.get_index():
|
|
|
|
page = wiki.get_page(entry['name'])
|
2015-09-26 02:35:16 +03:00
|
|
|
if not page:
|
|
|
|
# Some non-markdown files may have issues
|
|
|
|
continue
|
2014-11-13 01:06:56 +02:00
|
|
|
name = filename_to_cname(page['name'])
|
|
|
|
# TODO add email?
|
|
|
|
body = dict(name=name,
|
|
|
|
content=page['data'],
|
|
|
|
message=page['info']['message'],
|
|
|
|
username=page['info']['author'],
|
|
|
|
updated_on=entry['mtime'],
|
|
|
|
created_on=entry['ctime'])
|
2014-11-17 19:25:26 +02:00
|
|
|
search.index_wiki(name, body)
|