aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-11-30 10:36:55 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-11-30 10:36:55 +0100
commit68f00aad2e6980533021532c25582f4931608657 (patch)
tree27df7b9618438242e06df67708fecbf1027ad3ad
parentDo not check at all the content. (diff)
downloadnewspipe-68f00aad2e6980533021532c25582f4931608657.tar.gz
newspipe-68f00aad2e6980533021532c25582f4931608657.tar.bz2
newspipe-68f00aad2e6980533021532c25582f4931608657.zip
Database is now indexed in background.
-rw-r--r--pyaggr3g470r/decorators.py1
-rw-r--r--pyaggr3g470r/search.py16
-rw-r--r--pyaggr3g470r/views.py4
3 files changed, 15 insertions, 6 deletions
diff --git a/pyaggr3g470r/decorators.py b/pyaggr3g470r/decorators.py
index 80568add..5cacb09f 100644
--- a/pyaggr3g470r/decorators.py
+++ b/pyaggr3g470r/decorators.py
@@ -19,7 +19,6 @@ def async(f):
thr.start()
return wrapper
-
def feed_access_required(func):
"""
This decorator enables to check if a user has access to a feed.
diff --git a/pyaggr3g470r/search.py b/pyaggr3g470r/search.py
index 3f619e3c..b9e0ade7 100644
--- a/pyaggr3g470r/search.py
+++ b/pyaggr3g470r/search.py
@@ -27,6 +27,7 @@ __copyright__ = "Copyright (c) Cedric Bonhomme"
__license__ = "AGPLv3"
import os
+import logging
from whoosh.index import create_in, open_dir
from whoosh.index import EmptyIndexError
@@ -36,8 +37,12 @@ from whoosh.qparser import QueryParser
from whoosh.writing import AsyncWriter
from collections import defaultdict
+from pyaggr3g470r.models import User
+from pyaggr3g470r.decorators import async
from pyaggr3g470r import utils
+logger = logging.getLogger(__name__)
+
indexdir = "./pyaggr3g470r/var/indexdir"
schema = Schema(title=TEXT,
@@ -46,16 +51,21 @@ schema = Schema(title=TEXT,
feed_id=NUMERIC(int, stored=True),
user_id=NUMERIC(int, stored=True))
-
-def create_index(user):
+@async
+def create_index(user_id):
"""
Creates the index.
"""
+ user = User.query.filter(User.id == user_id).first()
+ logger.info("Starting indexation of the database.")
if not os.path.exists(indexdir):
os.makedirs(indexdir)
ix = create_in(indexdir, schema)
writer = ix.writer()
+ logger.info("Starting now.")
+ logger.info("Test: "+ user.nickname)
for feed in user.feeds:
+ logger.info("Indexing " +feed.title)
for article in feed.articles:
writer.add_document(title=article.title,
content=utils.clear_string(article.content),
@@ -63,7 +73,7 @@ def create_index(user):
feed_id=feed.id,
user_id=user.id)
writer.commit()
-
+ logger.info("Indexation done.")
def add_to_index(user_id, articles, feed):
"""
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index aec5c976..bec9f5ba 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -496,8 +496,8 @@ def index_database():
if not conf.ON_HEROKU:
user = User.query.filter(User.id == g.user.id).first()
try:
- fastsearch.create_index(user)
- flash(gettext('Database indexed.'), 'success')
+ fastsearch.create_index(user.id)
+ flash(gettext('Indexing database...'), 'success')
except Exception as e:
flash(gettext('An error occured') + ' (%s).' % e, 'danger')
return redirect(url_for('home'))
bgstack15