aboutsummaryrefslogtreecommitdiff
path: root/source/mongodb.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-01-11 18:35:50 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-01-11 18:35:50 +0100
commit216315958b8af26150562eee634bf4774904c0a6 (patch)
treeee4799e8f4a84a5c874aa4cd9d30e2c2536ea65d /source/mongodb.py
parentWe'll try a simple index searching algorithm. (diff)
downloadnewspipe-216315958b8af26150562eee634bf4774904c0a6.tar.gz
newspipe-216315958b8af26150562eee634bf4774904c0a6.tar.bz2
newspipe-216315958b8af26150562eee634bf4774904c0a6.zip
Search function now using MongoDB indexed fulltext searching.
Diffstat (limited to 'source/mongodb.py')
-rw-r--r--source/mongodb.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index 846a7a82..e91fb90b 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -47,7 +47,8 @@ class Articles(object):
Creates a new collection for a new feed.
"""
collection = self.db[new_collection["feed_id"]]
- #collection.create_index([("feed_link", pymongo.ASCENDING)], {"unique":True, "sparse":True})
+ collection.create_index([("article_date", pymongo.DESCENDING)], {"unique":False, "sparse":False})
+ collection.ensure_index('article_content', pymongo.ASCENDING)
collection.insert(new_collection)
def add_articles(self, articles, feed_id):
@@ -56,6 +57,8 @@ class Articles(object):
"""
collection = self.db[str(feed_id)]
#collection.create_index([("article_date", pymongo.DESCENDING)], {"unique":False, "sparse":False})
+ #collection.ensure_index('article_content', pymongo.ASCENDING)
+ print(collection.index_information())
for article in articles:
cursor = collection.find({"article_id":article["article_id"]})
if cursor.count() == 0:
@@ -219,6 +222,17 @@ class Articles(object):
collection = self.db[str(feed_id)]
collection.update({"type": 0, "feed_id":feed_id}, {"$set": changes}, multi=True)
+ def full_search(self, term):
+ """
+ Indexed full text search through content of articles.
+ """
+ articles = {}
+ for collection in self.get_all_feeds():
+ result = self.db[collection["feed_id"]].find({'article_content': {'$regex': term, "$options": 'i' }})
+ if result.count() != 0:
+ articles[collection["feed_id"]] = result.sort([("article_date", pymongo.DESCENDING)])
+ return articles
+
# Functions on database
def drop_database(self):
"""
bgstack15