diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-07-24 14:24:54 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-07-24 14:24:54 +0200 |
commit | 7044f4676a083fc85c1092cf31eeda3dd279915d (patch) | |
tree | f36892898e2c06e1f4496f9c890d155252c1a48e | |
parent | Fixed an URL in the README. (diff) | |
download | newspipe-7044f4676a083fc85c1092cf31eeda3dd279915d.tar.gz newspipe-7044f4676a083fc85c1092cf31eeda3dd279915d.tar.bz2 newspipe-7044f4676a083fc85c1092cf31eeda3dd279915d.zip |
added add_to_index function, to add an article to the Whoosh index.
-rwxr-xr-x | source/feedgetter.py | 4 | ||||
-rw-r--r-- | source/search.py | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/source/feedgetter.py b/source/feedgetter.py index 31a02d4b..bd9cacc9 100755 --- a/source/feedgetter.py +++ b/source/feedgetter.py @@ -34,6 +34,7 @@ from datetime import datetime from contextlib import contextmanager import conf +import search import utils import mongodb @@ -177,6 +178,9 @@ class FeedGetter(object): articles.append(article) + # add the article to the Whoosh index + #search.add_to_index([article], feed) + if conf.MAIL_ENABLED and feed["mail"] and self.articles.get_articles(feed_id, article_id) == False: # if subscribed to the feed AND if article not already in the database threading.Thread(None, utils.send_mail, None, (conf.mail_from, conf.mail_to, \ diff --git a/source/search.py b/source/search.py index e9e4c801..63abddc4 100644 --- a/source/search.py +++ b/source/search.py @@ -63,6 +63,22 @@ def create_index(): feed_id=feed["feed_id"]) writer.commit() +def add_to_index(articles, feed): + """ + Add a list of articles to the index. + """ + try: + ix = open_dir(indexdir) + except (EmptyIndexError, OSError) as e: + raise EmptyIndexError + writer = ix.writer() + for article in articles: + writer.add_document(title=article["article_title"], \ + content=utils.clear_string(article["article_content"]), \ + article_id=article["article_id"] , \ + feed_id=feed["feed_id"]) + writer.commit() + def search(term): """ Search for `term` in the index. @@ -82,4 +98,4 @@ if __name__ == "__main__": #create_index() results = search("Nothomb") for article in results: - print(article)
\ No newline at end of file + print(article) |