aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsource/pyAggr3g470r.py6
-rw-r--r--source/search.py10
2 files changed, 12 insertions, 4 deletions
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index 4f006571..07782924 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -48,6 +48,7 @@ import time
import datetime
from collections import defaultdict
+from whoosh.index import EmptyIndexError
import cherrypy
from mako.template import Template
@@ -170,7 +171,10 @@ class pyAggr3g470r(object):
if param == "Feed":
feed_id, _, query = value.partition(':')
search_result = defaultdict(list)
- results = search.search(param)
+ try:
+ results = search.search(param)
+ except EmptyIndexError as e:
+ return self.error('<p>The database has not been <a href="/index_base">indexed</a>.</p>')
for result in results:
article = self.mongo.get_articles(result[0], result[1])
search_result[result[0]].append(article)
diff --git a/source/search.py b/source/search.py
index 7eb4b065..e9e4c801 100644
--- a/source/search.py
+++ b/source/search.py
@@ -20,15 +20,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
__author__ = "Cedric Bonhomme"
-__version__ = "$Revision: 0.1 $"
+__version__ = "$Revision: 0.2 $"
__date__ = "$Date: 2013/06/24 $"
-__revision__ = "$Date: 2013/06/24 $"
+__revision__ = "$Date: 2013/06/25 $"
__copyright__ = "Copyright (c) Cedric Bonhomme"
__license__ = "GPLv3"
import os
from whoosh.index import create_in, open_dir
+from whoosh.index import EmptyIndexError
from whoosh.fields import *
from whoosh.qparser import QueryParser
@@ -67,7 +68,10 @@ def search(term):
Search for `term` in the index.
Returns a list of articles.
"""
- ix = open_dir(indexdir)
+ try:
+ ix = open_dir(indexdir)
+ except (EmptyIndexError, OSError) as e:
+ raise EmptyIndexError
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(term)
results = searcher.search(query, limit=None)
bgstack15