More changes to related_posts

This commit is contained in:
Samrat Man Singh 2012-07-10 20:43:43 +05:45
commit 53a1c21a98

View file

@ -349,20 +349,16 @@ class ArticlesGenerator(Generator):
for article in self.articles: for article in self.articles:
article.related_posts = [] article.related_posts = []
relation_score = {} relation_score = {}
if article.tags: try:
article_tags = article.tags article_tags = article.tags
for tag in article_tags: for tag in article_tags:
try: for related_article in self.tags[tag]:
for related_article in self.tags[tag]: article.related_posts.append(related_article)
article.related_posts.append(related_article) article.related_posts.reverse()
article.related_posts.reverse()
except: except: # can't find any related posts
article.related_posts = potential_related[:5] pass
#article.related_posts = all_articles[:5].reverse()
elif len(article.related_posts) == 0: # article doesn't have tags
print "No tags for ", article.title
article.related_posts = all_articles[:5].reverse()
relation_score = dict( \ relation_score = dict( \
zip(set(article.related_posts), \ zip(set(article.related_posts), \
@ -370,6 +366,7 @@ class ArticlesGenerator(Generator):
set(article.related_posts)))) set(article.related_posts))))
ranked_related = sorted(relation_score, key=relation_score.get) ranked_related = sorted(relation_score, key=relation_score.get)
article.related_posts = ranked_related article.related_posts = ranked_related
try: # make sure article doesn't appear in its own related posts try: # make sure article doesn't appear in its own related posts