MP: lets take this example
Post1 has tag1, tag2, tag3
Post2 has tag1, tag2
post3 has tag1, tag2, tag3
post4 has tag1
post 1 has more in common with post3 then with anything else
then it has partially somethings in common with post2, the last one is post4
if you ever want to show related posts with post1, the order that you need to show is post3, post2, post4
so what I am proposing besides the power of your tag search is to have a related posts relation maybe directly in the behavior, that would take all of the post1 tags, select from the relation table all of the post that have those, make a grouping on post_id and a count on tag_id, order by count(tag_id) and return the posts based on the post_id column
MP: I am not sure it is possible directly in the behavior
AK: I think its possible by TaggableQuery
AK: Just need to think about implementation.
AK: And method name.
AK: I mean it should be scope.
AK: Like tag()
AK: But need to think about that scope name.
AK: Maybe recent()
MP: just some food for thought
AK: Can you create issue with that?
MP: ok, sure
AK: To not forget implement it as future plans.
AK: Because it very serious and interesting feature.
AK: Moreover since behavior is entity related it 100% possible
AK: relatedByTags() maybe...
AK: But we need to think about optimal implementation on SQL level.
MP: we might need too much info put in the behavior...
AK: It will looks like:
Post::find()->relatedByTags(... tags here...)->all();
$post->relatedByTags(... no params here...)->all();
MP: lets take this example Post1 has tag1, tag2, tag3 Post2 has tag1, tag2 post3 has tag1, tag2, tag3 post4 has tag1
post 1 has more in common with post3 then with anything else then it has partially somethings in common with post2, the last one is post4 if you ever want to show related posts with post1, the order that you need to show is post3, post2, post4
so what I am proposing besides the power of your tag search is to have a related posts relation maybe directly in the behavior, that would take all of the post1 tags, select from the relation table all of the post that have those, make a grouping on post_id and a count on tag_id, order by count(tag_id) and return the posts based on the post_id column MP: I am not sure it is possible directly in the behavior AK: I think its possible by TaggableQuery AK: Just need to think about implementation. AK: And method name. AK: I mean it should be scope. AK: Like tag() AK: But need to think about that scope name. AK: Maybe recent() MP: just some food for thought AK: Can you create issue with that? MP: ok, sure AK: To not forget implement it as future plans. AK: Because it very serious and interesting feature. AK: Moreover since behavior is entity related it 100% possible AK: relatedByTags() maybe... AK: But we need to think about optimal implementation on SQL level. MP: we might need too much info put in the behavior... AK: It will looks like:
Post::find()->relatedByTags(... tags here...)->all(); $post->relatedByTags(... no params here...)->all();