Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:44:29+00:00 2026-06-04T01:44:29+00:00

We have a posting analyzing requirement, that is, for a specific post, we need

  • 0

We have a posting analyzing requirement, that is, for a specific post, we need to return a list of posts which are mostly related to it, the logic is comparing the count of common tags in the posts. For example:

    postA = {"author":"abc",
        "title":"blah blah",
        "tags":["japan","japanese style","england"],
    }

there are may be other posts with tags like:

postB:["japan", "england"]
postC:["japan"]
postD:["joke"]

so basically, postB gets 2 counts, postC gets 1 counts when comparing to the tags in the postA. postD gets 0 and will not be included in the result.

My understanding for now is to use map/reduce to produce the result, I understand the basic usage of map/reduce, but I can’t figure out a solution for this specific purpose.

Any help? Or is there a better way like custom sorting function to work it out? I’m currently using the pymongodb as I’m python developer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:44:30+00:00Added an answer on June 4, 2026 at 1:44 am

    You should create an index on tags:

    db.posts.ensure_index([('tags', 1)])
    

    and search for posts that share at least one tag with postA:

    posts = list(db.posts.find({_id: {$ne: postA['_id']}, 'tags': {'$in': postA['tags']}}))
    

    and finally, sort by intersection in Python:

    key = lambda post: len(tag for tag in post['tags'] if tag in postA['tags'])
    posts.sort(key=key, reverse=True)
    

    Note that if postA shares at least one tag with a large number of other posts this won’t perform well, because you’ll send so much data from Mongo to your application; unfortunately there’s no way to sort and limit by the size of the intersection using Mongo itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page that uses cross page posting to post to a
I have searched before posting but none of the posts are that relevant (saying
I am posting this in hopes that someone might have dealt with a similar
Posting this one for a friend. They have an Icefaces app that uses Icefaces's
this is my first time posting here, I have a question which I have
I have Ajax.ActionLink that POSTS to a method on a controller and passes an
I have an application in which I am posting data to my server API
I have a DetailsView that I'm posting back - and inside of that is
I have a client that will be posting large JSON files to an API
I have an jquery .ajax posting to a asp.net mvc method that has an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.