Changeset - 8b6e87245e57
[Not reviewed]
default
0 1 0
Mads Kiilerich - 7 years ago 2018-12-23 21:16:07
mads@kiilerich.com
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'
1 file changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/search.py
Show inline comments
 
@@ -28,13 +28,13 @@ Original author and date, and relevant c
 
import logging
 
import traceback
 
import urllib
 
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
 

	
 
from kallithea.lib.auth import LoginRequired
 
from kallithea.lib.base import BaseRepoController, render
 
@@ -81,15 +81,17 @@ class SearchController(BaseRepoControlle
 
            cur_query = c.cur_query.lower()
 
            log.debug(cur_query)
 

	
 
        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)
 
                if c.repo_name:
 
                    # use "repository_rawname:" instead of "repository:"
 
                    # for case-sensitive matching
 
@@ -130,13 +132,13 @@ class SearchController(BaseRepoControlle
 
                        url=url_generator
 
                    )
 

	
 
                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. '
 
                              'Please run whoosh indexer')
 
            except Exception:
 
                log.error(traceback.format_exc())
0 comments (0 inline, 0 general)