diff options
Diffstat (limited to 'source/search.py')
-rw-r--r-- | source/search.py | 14 |
1 files changed, 14 insertions, 0 deletions
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. |