Generate related posts based on tags. Sort by the number of shared tags.
- Read the posts JSON file.
- Iterate over the posts and populate a map containing:
tag -> List<Post>
that has that tag - Iterate over the posts and for each post:
- Create a map:
Post -> int
to track the number of shared tags - For each tag, Iterate over the posts that have that tag
- For each post, increment the shared tag count in the map.
- Create a map:
- Sort the related posts by the number of shared tags.
- Write the top 5 related posts for each post to a new JSON file.
./run.sh go | rust | python | all
Language | Time (avg) |
---|---|
Go | 0.55s |
Rust | 0.04s |
Rust (Rayon) | 0.02s |
Python | 7.81s |