aboutsummaryrefslogtreecommitdiff
path: root/source/search.py
diff options
context:
space:
mode:
Diffstat (limited to 'source/search.py')
-rw-r--r--source/search.py18
1 files changed, 17 insertions, 1 deletions
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)
bgstack15