Mercurial > kallithea
changeset 7451:8b6e87245e57
search: Actually raise EmptyIndexError if the index hasn't been built yet
It would only log a generic error with:
OSError: [Errno 2] No such file or directory: '.../data/index'
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 23 Dec 2018 21:16:07 +0100 |
parents | 1c4007ec86e8 |
children | d5ab6db3b9e2 |
files | kallithea/controllers/search.py |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/search.py Sun Dec 23 21:16:06 2018 +0100 +++ b/kallithea/controllers/search.py Sun Dec 23 21:16:07 2018 +0100 @@ -31,7 +31,7 @@ from tg.i18n import ugettext as _ from tg import request, config, tmpl_context as c -from whoosh.index import open_dir, EmptyIndexError +from whoosh.index import open_dir, exists_in, EmptyIndexError from whoosh.qparser import QueryParser, QueryParserError from whoosh.query import Phrase, Prefix from webhelpers.util import update_params @@ -84,9 +84,11 @@ if c.cur_query: p = safe_int(request.GET.get('page'), 1) highlight_items = set() + index_dir = config['app_conf']['index_dir'] try: - idx = open_dir(config['app_conf']['index_dir'], - indexname=index_name) + if not exists_in(index_dir, index_name): + raise EmptyIndexError + idx = open_dir(index_dir, indexname=index_name) searcher = idx.searcher() qp = QueryParser(search_type, schema=schema_defn) @@ -133,7 +135,7 @@ except QueryParserError: c.runtime = _('Invalid search query. Try quoting it.') searcher.close() - except (EmptyIndexError, IOError): + except EmptyIndexError: log.error(traceback.format_exc()) log.error('Empty Index data') c.runtime = _('There is no index to search in. '