站長阿川 🌏  ·  4年前

梗圖倉庫大部份模組使用的熱門演算法公式

網站很多地方都有用到「熱門」的排序

目前站長是用一個簡單的公式,未來可能會再改成比較複雜的公式

跟大家分享目前的公式

function refreshTrendingScore()
{
    if ($this->approved_at < \Carbon\Carbon::now()->subHours(
        24 * trending_image_beginning_live_days() + $this->total_like_count * trending_image_extra_hours_per_like()
    )) {
        $this->trending_score = 0;

        $this->save();

        return;
    }

    $score = 0;

    if ($this->user_id != 0) {
        $score += 100;

        if ($this->user->intro) $score += 2;

        if ($this->user->photo) $score += 2;

        if ($this->user->created_at >= \Carbon\Carbon::now()->subDays(2) ||
            $this->user->wtf_total_count < 4)
        {
            $score += 4;
        }
    }

    if ($this->hashtag != '') $score += 2;

    if ($this->contest_id != 0) $score += 2;

    // $score = $score + floor($this->pageview / 1000) * 0;

    $userId = $this->user_id;

    $score += $this->likes->filter(function($like) use ($userId) { return $userId != $like->user_id; })->count() * 10;

    if ($this->comments->filter(function($comment) use ($userId) { return $userId != $comment->user_id; })->count() > 0) {
        $score += 10;
    }

    if ($score >= 10) {
        $this->trending_score = $score;
    } else {
        $this->trending_score = 0;
    }

    if ($this->is_sensitive) {
        $this->trending_score = 0;
    }

    $this->save();
}

是一個很簡單好用的小小熱門公式

跟大家分享唷~

按讚的人:

共有 1 則留言

§藍龍§ 🇹🇼 4年前

迴圈?

按讚的人:
程式設計討論
程式設計、軟體工程相關的自由交流區~
  加入部落
建立日期:2021年06月20日