7 hours ago · Tech · hide · 0 comments

♠ Previously. Problem statement: post connections showed only direct links, while posts with the same tags remained disconnected in the graph of this blog. I added a second kind of edge. The pre-computation picks up to two posts with the most shared tags, breaks ties by date, and excludes direct links: def compute_tag_related_posts( post: dict, all_posts: list[dict], outlinks_set: set[str], backlinks_set: set[str], limit: int = 2, ) -> list[str]: """Compute tag connections, excluding posts with direct links.""" post_tags = set(post["tags"]) if not post_tags: return [] direct_ids = outlinks_set | backlinks_set scored = [] for other in all_posts: other_id = other["id"] if other_id == post["id"] or other_id in direct_ids: continue shared_tags = post_tags & set(other["tags"]) if shared_tags: scored.append((other_id, len(shared_tags), other["date"])) scored.sort(key=lambda item: (item[1], item[2], item[0]), reverse=True) return [item[0] for item in scored[:limit]] Direct links remain…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.