aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-07-25 07:55:30 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-07-25 07:55:30 +0200
commit80cef7164764a9a73857cd6abf511e1204a5bf90 (patch)
tree9359d0c245f123c257493a6f309d7facf5971c47
parentfixed a really strange bug... to investigate... (diff)
downloadnewspipe-80cef7164764a9a73857cd6abf511e1204a5bf90.tar.gz
newspipe-80cef7164764a9a73857cd6abf511e1204a5bf90.tar.bz2
newspipe-80cef7164764a9a73857cd6abf511e1204a5bf90.zip
The Whoosh index stays now in sync with the MongoDB database.
-rwxr-xr-xsource/pyAggr3g470r.py7
-rw-r--r--source/search.py14
2 files changed, 19 insertions, 2 deletions
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index cf0af11e..ad43bda6 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -602,9 +602,12 @@ class pyAggr3g470r(object):
"""
try:
feed_id, article_id = param.split(':')
+ # Delete from the MonfoDB database
self.mongo.delete_article(feed_id, article_id)
- except:
- return self.error("<p>Bad URL. This article do not exists.</p>")
+ # Delete from the Whoosh index
+ search.delete_article(feed_id, article_id)
+ except Exception as e:
+ return self.error("<p>Bad URL. This article do not exists.</p>"+str(e))
return self.index()
diff --git a/source/search.py b/source/search.py
index f38133eb..d9c8ad59 100644
--- a/source/search.py
+++ b/source/search.py
@@ -31,6 +31,7 @@ import os
from whoosh.index import create_in, open_dir
from whoosh.index import EmptyIndexError
from whoosh.fields import *
+from whoosh.query import *
from whoosh.qparser import QueryParser
from whoosh.writing import AsyncWriter
@@ -82,6 +83,19 @@ def add_to_index(articles, feed):
feed_id=feed["feed_id"])
writer.commit()
+def delete_article(feed_id, article_id):
+ """
+ Delete an article from the index.
+ """
+ try:
+ ix = open_dir(indexdir)
+ except (EmptyIndexError, OSError) as e:
+ raise EmptyIndexError
+ writer = ix.writer()
+ document = And([Term("feed_id", feed_id), Term("article_id", article_id)])
+ writer.delete_by_query(document)
+ writer.commit()
+
def search(term):
"""
Search for `term` in the index.
bgstack15