Nqxcode\LuceneSearch\Model\Config::boost PHP Method

boost() public method

Get boost for model.
public boost ( Model $model ) : integer
$model Illuminate\Database\Eloquent\Model
return integer
    public function boost(Model $model)
    {
        $boost = 1;
        $c = $this->config($model);
        $option = snake_case(__FUNCTION__);
        if (!is_null(array_get($c, $option))) {
            $accessor = array_get($c, $option) === true ? $option : array_get($c, "{$option}.accessor");
            if (!is_null($accessor)) {
                $boost = $model->{$accessor} ?: 1;
            }
        }
        return $boost;
    }

Usage Example

 public function testBoost()
 {
     $this->productMock->shouldReceive('getAttribute')->with('boost')->andReturn(0.5)->byDefault();
     $this->dummyMock->shouldReceive('getAttribute')->with('custom_boost_accessor')->andReturn(0.3)->byDefault();
     $actual = $this->config->boost($this->productMock);
     $this->assertEquals(0.5, $actual);
     $actual = $this->config->boost($this->dummyMock);
     $this->assertEquals(0.3, $actual);
 }
All Usage Examples Of Nqxcode\LuceneSearch\Model\Config::boost