aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/search.py
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 /pyaggr3g470r/search.py
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.
Diffstat (limited to 'pyaggr3g470r/search.py')
-rw-r--r--pyaggr3g470r/search.py16
1 files changed, 13 insertions, 3 deletions
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):
"""
bgstack15