定制 nikolajlovenhardt/laravel-edgerank 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nikolajlovenhardt/laravel-edgerank

最新稳定版本:0.0.1

Composer 安装命令:

composer require nikolajlovenhardt/laravel-edgerank

包简介

Facebook Edgerank Algorithm for Laravel

README 文档

README

This package is a simple and flexible implementation of the Facebook EdgeRank algorithm for Laravel. Ideal for newsfeeds like Twitter, Facebook, LinkedIn, etc. Use the EdgeRank algorithm to sort posts and similar content based on factors such as likes, comments, shares, and time. The configuration makes it easy to manage the weighting of different parameters.

Installation and setup

Installation with Composer

composer require nikolajlovenhardt/laravel-edgerank

Publish resources

Config

php artisan vendor:publish --tag="edgerank-config"

Migrations

php artisan vendor:publish --tag="edgerank-migrations"

Use-cases and demos

Sort posts using default weights

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->get();

Limits and offsets

Simple pagination

Paginate with a simple limit and offset

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->limit(50)
    ->offset(100)
    ->get();

Cursor

Do you need to paginate using ids? No worries, we got your back

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->after(100, 'id') // Get older posts than #100
    ->get();

Custom query

Use the $builder->query() method to access the query builder before fetching the results. This allows you to add custom query code still utilizing the EdgeRank-sort.

use LaravelEdgeRank\Builders\EdgeRankBuilder;
use App\Models\Feed\Item;

$friendIds = [1, 2, 3, 4];

$posts = EdgeRankBuilder::make(Item::class)
    ->query()
    ->where(function ($query) use ($friendIds) {
        $query->whereIn('user_id', $friendIds)
        
        $query->orWhereHas('user', function () {
            $query->where('is_public', '=', true)
        });
    })
    ->get();

Custom model / Override config

Use a custom model without configuration using the EdgeRankBuilder::make() method, and add custom config using weights()and options()-methods.

use LaravelEdgeRank\Builders\EdgeRankBuilder;
use App\Models\Feed\Item;

$posts = EdgeRankBuilder::make(Item::class)
    ->weights([
        'likes' => 10,
        'hates' => 2,
        'customRelation' => 1.5, // Item->customRelation(): HasMany
    ])
    ->get();

Contributing

Thank you for considering contributing to Laravel EdgeRank!

License

Laravel EdgeRank is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-12