PHP code example of muradyanvano / php-lexorank

1. Go to this page and download the library: Download muradyanvano/php-lexorank library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

muradyanvano / php-lexorank example snippets


use MuradyanVano\LexoRank\LexoRank;
use MuradyanVano\LexoRank\LexoRankService;

$first = LexoRank::middle();           // 0|hzzzzz:
$second = $first->after();             // strictly after first
$between = $first->between($second);   // strictly between

$service = new LexoRankService();
$bulk = $service->initialRanks(10);    // 10 evenly spaced ranks in bucket 0

use MuradyanVano\LexoRank\LexoRankBucket;

LexoRank::middle()->inNextBucket()->toString(); // 1|hzzzzz:
LexoRankBucket::bucket0()->next();              // bucket1

$rank = LexoRank::parse('0|100000:');
$rank->between(LexoRank::parse('0|200000:'));
$rank->before();
$rank->after();

$service = new LexoRankService();
$service->between($lower, $upper);
$service->betweenMany(null, null, 50);
$service->initialRanks(5, LexoRankBucket::bucket1());

use MuradyanVano\LexoRank\LexoRankCollection;

$collection = LexoRankCollection::from(['0|100000:', '0|300000:']);
$sorted = $collection->sorted();
$collection->assertStrictlyOrdered();
$collection->duplicates();
$collection->suggestsRebalance(); // default soft length 64
$collection->rankForInsertAt(1); // rank between index 0 and 1

use MuradyanVano\LexoRank\Rebalancer;

$rebalancer = new Rebalancer();
$result = $rebalancer->rebalance($orderedRankStrings);

$result->bucket();
$result->mapping(); // old => new
$result->map('0|very-long-rank:');

$rebalancer->shouldRebalance($ranks, softLength: 64);

protected $casts = ['rank' => \MuradyanVano\LexoRank\Laravel\Casts\LexoRankCast::class];

use MuradyanVano\LexoRank\Laravel\Concerns\HasLexoRank;

$task->moveBetween($before, $after);
$task->moveAfterAndSave($other);
Task::query()->orderByRank()->get();

use MuradyanVano\LexoRank\Laravel\Facades\LexoRank as LexoRankFacade;

LexoRankFacade::between($lower, $upper);
LexoRankFacade::rebalance($ranks);

$table->string('rank', 255)->nullable()->unique();
bash
composer 
bash
php artisan vendor:publish --tag=lexorank-config
bash
git clone https://github.com/muradyanvano/php-lexorank.git
cd php-lexorank
composer update
composer check    # validate + format-check + phpstan + core tests (PHP 8.1+)