Merge branch 'master' into history_optimization

# Conflicts:
#	realms/modules/search/commands.py
This commit is contained in:
Chase Sterling 2016-07-13 20:48:28 -04:00
commit 7487a65314
4 changed files with 32 additions and 34 deletions

View file

@ -2,10 +2,10 @@ import click
from realms.lib.util import random_string
from realms.modules.auth.local.models import User
from realms.lib.util import green, red, yellow
from realms import flask_cli
from realms import cli_group
@flask_cli.group(short_help="Auth Module")
@cli_group(short_help="Auth Module")
def cli():
pass

View file

@ -1,10 +1,10 @@
import click
from realms import create_app, search, flask_cli
from flask import current_app
from realms import search, cli_group
from realms.modules.wiki.models import Wiki
from realms.lib.util import filename_to_cname
@flask_cli.group(short_help="Search Module")
@cli_group(short_help="Search Module")
def cli():
pass
@ -13,29 +13,25 @@ def cli():
def rebuild_index():
""" Rebuild search index
"""
app = create_app()
if app.config.get('SEARCH_TYPE') == 'simple':
if current_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'])
if not page:
# Some non-markdown files may have issues
continue
name = filename_to_cname(page['path'])
# TODO add email?
# TODO I have concens about indexing the commit info from latest revision, see #148
info = next(page.history)
body = dict(name=name,
content=page.data,
message=info['message'],
username=info['author'],
updated_on=entry['mtime'],
created_on=entry['ctime'])
search.index_wiki(name, body)
# 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?
# TODO I have concens about indexing the commit info from latest revision, see #148
info = next(page.history)
body = dict(name=page.name,
content=page.data,
message=info['message'],
username=info['author'],
updated_on=entry['mtime'],
created_on=entry['ctime'])
search.index_wiki(page.name, body)