jeudi 12 avril 2018

Laravel implementation of "Similar Tags"

I have a list of tags. For each tag, I want to find the similar tags. For example, if user has clicked on "angular", I want to find tags like "typescript", "angular-routing", "angular-services" etc.

I do not have a table structure where I associate one tag with another. I have a 'Post' table and a 'Tag' table in a Many-to-Many relationship. What I mean by "similar tags" are tags that are often used together in a Post.

$posts = Tag::find($tagId)->posts()->get();
foreach($posts as $post){
    //what should I do here?        
}

I'm getting all the posts with the particular 'tag'. Now I'm thinking I should iterate over the post collection and store the tags associated with each post in an array. And then sort the array based on frequency.

But I feel maybe it's not the right approach. I have seeded my database with huge amount of data and perhaps this will slow down the entire application. Also, I'm not very confident about implementing that. Can anyone help me with this? Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire