Skip to main content
Topic: Hashtags (Read 5467 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Hashtags

Tags are used in a lot of forum software as either an addon or a default feature. Hashtags are used in social networks like Twitter and Facebook. Forum posts often turn in to more than just the original topic and become a conversation. Conversations evolve with many topics so the original post might not directly pertain to the last.

Okay, enough about that. We all know what hashtags are. #hashtag #forum #addon #maybeDefaultFeature #wouldBeReallyCool

Anyway... this isn't something I'm likely to develop right now so if anyone wants to tackle it, I'll post how I'd do it.

On the display page, just use a preg_replace for #hashtag and replace with a link to the view tags action.

I don't think there's any reason to have anything more on the post page than making the hashtag bold on the WYSIWYG editor.

On post, just grep the hashtags. There will be two tables, hashtags and post_hashtags. Hashtags is two fields: id_tag and tag (varchar). post_hashtags is id_tag and id_post. After thinking through this, I think post_hashtags needs to have a timestamp for trending. It will also have to remove hashtags, so compare that as well.

Then we need some actions. ?action=hashtag with two subactions: &sa=search &sa=trending

When you click a hashtag it will take you to the search action with &tag=[your hashtag]. Or, if there is no tag to search, it just shows a search screen and the trending beneath that. The trending subaction will show the "hot" tags. 

Searching just looks for posts that match the tag. That's easy. The hard part is the trending and the permissions. Speaking of permissions, add a couple for search_tags, view_trends.

Thinking about settings and number of tags to trend should be one of them. Maybe default is 5. Frequency of trending update: 1/hour. Maybe on the search page, group topics?

Should posts that you can't see contribute towards trends? I think if they didn't, the query becomes extremely difficult.

Re: Hashtags

Reply #1

Instead of having a "search" subaction, just make the default action "search" and if there is a tag to search for, it will replace ?action=hashtags;sa=search;tag=myhashtag

Oh, before placing in the hashtags table, lowercase the string.

Re: Hashtags

Reply #2

I started a long while ago working on something like that:
https://github.com/emanuele45/topic_tags/tree/hashtags
never managed to finish it... as usual. LOL

Now that I look again at the repo I noticed I never added the db schema... :-[
What I did were two tables:
{db_prefix}tag_terms with id_term , tag_text, times_used
{db_prefix}tag_relation with id_term, id_topic, times_mentioned
the first keeps a track of each tag and the overall usage, while the second holds the relation between the tag and the topic (plus usage within the topic).
I have always wondered if it was better to track at message level, though I never really found "The answer".

I posted also some screenshots: http://www.elkarte.net/community/index.php?topic=423.0 (darn they are OLD!!! ROFL)

Trends is something I underestimated at first because the addon was intended for "classic" tags, but it's something that should be there.

ETA: that code is actually live on a couple of sites.
Bugs creator.
Features destroyer.
Template killer.

Re: Hashtags

Reply #3

Yeah, that's a wee bit different from hashtags though.

Okay, trending is going to be pretty difficult to calculate. If it's on a site like this one, where you don't get 1000 posts a day, it might not get any trending posts, especially if nobody is using hashtags. So should it show "Nothing is trending right now, use hashtags to start some trends" or should it keep digging deeper until it finds something to make a trend?

I think that might be a setting for the admin because digging deeper can cause some massive load.

Here's how I'm thinking it needs to be done. First, it will have to calculate how many posts with hashtags are made per hour. So, a query where it groups by the hour that the message was posted in the past 24 hours. It can be a longer time or a shorter time (maybe use a throttle there) but it probably should have a granularity of no greater than an hour and the span should be no less than 24 hours. Then it will start adding hours until it reaches 100 hashtags, also another throttle. Might want to have more than 100 to make a trend. After it figures out how many hours it needs to use, it will group by the tag and count, ordering by count. Then it will pick the top 5 or 10 or whatever the admin chooses. It will then cache those tags to the settings table.

Am I missing anything?

Obviously trending can only work as a scheduled task or cron.

Re: Hashtags

Reply #4

I think this is the idea. I can understand it.

Code: [Select]
<?php

class Trends
{
public function trending($min_tag_count = 100, $num_tags = 5)
{
// Get the number of hours
$num_hours = $this->getNumHoursToStartTrend($min_tag_count);

$tags = $this->getTagsByCountAndTime($num_hours);

// Get the first $num_tags
return array_slice($tags, 0, $num_tags);
}

protected function getNumHoursToStartTrend($min_tag_count = 100)
{
$hours = [];
do
{
$hours += $this->getNumTagsByHour();

// Add a day to the start date.

}while (count($hours) < $min_tag_count);

return $num_hours;
}

protected function getNumTagsByHour(\DateTime $start_date = 'NOW()', $num_hours = 24)
{
/*
* Group the number of tags by hour:
*
* SELECT HOUR(tag_dtg) AS tag_hour, COUNT(*) as hour_count
* FROM post_tags
* WHERE tag_dtg >= $start_date - $num_hours HOURS
* GROUP BY HOUR(tag_dtg)
* ORDER BY tag_hour
*/

return $hours;
}

protected function getTagsByCountAndTime($hours_from_now)
{
/*
* Get all of the tags in this timeframe
*
* SELECT tag, COUNT(*) as tag_count
* FROM post_tags
* INNER JOIN tags USING(id_tag)
* WHERE tag_dtg >= NOW() - $hours_from_now HOURS
* GROUP BY id_tag
* ORDER BY tag_count
*/

return $tags;
}
}

Re: Hashtags

Reply #5

Quote from: Joshua Dickerson – Yeah, that's a wee bit different from hashtags though.
???
Did you read the last (or close to last) posts? It started as "normal" tags, but it can work as hashtags in the branch I'm (kind of) developing. ;)
Bugs creator.
Features destroyer.
Template killer.


Re: Hashtags

Reply #7

Not from me.
I'm working on few other things.
I may tweak a bit my addon, but not sure when. Of course, if anyone is interested in giving a try no problem. ;)
Bugs creator.
Features destroyer.
Template killer.


Re: Hashtags

Reply #9

Nope, not yet.
I need one myself, but at the moment I have few other priorities... :(
Bugs creator.
Features destroyer.
Template killer.

Re: Hashtags

Reply #10

Plant a tree, build a house, raise a child?  ;)

Re: Hashtags

Reply #11

How Instagram does trends: http://instagram-engineering.tumblr.com/post/122961624217/trending-at-instagram

Thinking about how I labeled trends here, it isn't really what a trend is. IG defines it better. I think still using the "trend" moniker makes sense because you are unlikely to have true trends on a forum, but in the future, a real trending calculator might make sense for some really large forums.

Re: Hashtags

Reply #12

Quote from: Jorin – Plant a tree, build a house, raise a child?  ;)
Unlikely! lol
Bugs creator.
Features destroyer.
Template killer.

Re: Hashtags

Reply #13

Why is that unlikely? It is so likely... :)

Re: Hashtags

Reply #14

You don't know Italy well enough @ahrasis :(
~ SimplePortal Support Team ~