aboutsummaryrefslogtreecommitdiff
path: root/source/search.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-06-25 07:14:33 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-06-25 07:14:33 +0200
commit0a7dfb1c934ce29c09df31d3462a5113027d0cf4 (patch)
treee224260cec84db24a98da89fb2915ea59d3e3af2 /source/search.py
parentAdded a button to reindex the database on the /search page. (diff)
downloadnewspipe-0a7dfb1c934ce29c09df31d3462a5113027d0cf4.tar.gz
newspipe-0a7dfb1c934ce29c09df31d3462a5113027d0cf4.tar.bz2
newspipe-0a7dfb1c934ce29c09df31d3462a5113027d0cf4.zip
Test if the database has not been indexed.
Diffstat (limited to 'source/search.py')
-rw-r--r--source/search.py10
1 files changed, 7 insertions, 3 deletions
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