Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

grundig1313's avatar

"weighted" newsfeed

Hi,

I'm very interested in hearing your opinion about, which would be the best way of implementing a "weighted" newsfeed. So, actually a list of events (like the FB timeline) where some events have to be "better" positioned in the feed.

Any thoughts or pointers on patterns, papers, etc on the most flexible, efficient and powerful approaches for implementing such a system, data model, etc. would be appreciated.

Thanks! Simon

0 likes
5 replies
d3xt3r's avatar

This isn't trivial. There are 100s and 1000s of variables that goes into weight calculation, including but not limited to other user's interaction with certain feed. Plus, the weight calculated for a certain event will be different for you and me.

Start by studying the variables that define your event.

grundig1313's avatar

I't should not be that complicated. It's more about a concept on how to calculate such a weighting "on the fly" (or not).

willvincent's avatar
Level 54

Fairly trivial... Include a signed integer field to store the 'weight' value, default everything to 0. If a particular item needs to be 'better positioned' give it a lower (negative) number, if it should be toward the end of the list of items, give it a higher (positive) value. Then always include an orderby on the weight, in ascending order so lower values bubble up to the top. If you need to also sort by other criteria, use multiple orderby's.

It really doesn't need to be more complicated than that. Now, if you want items to float toward the top based on their popularity (how often they're viewed, etc) you could include some additional logic to dynamically update those items' weight values on the fly. You can of course complicate it as much as you want, but really.. a simple signed integer that is used with an orderby is probably sufficient.

If not -- give specific examples of what you need to achieve that you don't think that will accomplish. :)

d3xt3r's avatar

Fairly trivial... Include a signed integer field to store the 'weight' value

I didn't realise you were just looking for this. I thought,, it was more about how you calculate the weights

Please or to participate in this conversation.