Function Builder

The function builder is a simple helper class to help writing and maintaining functions for use with, for example (but not limited to), the analytics component.

As the resulting function can be casted to a string, the usage is pretty straightforward.



use Solarium\Builder\Analytics\FunctionBuilder;

// ...

$query = $client->createSelect();
$analytics = $query->getAnalytics();

$expr = FunctionBuilder::expr();
$builder = FunctionBuilder::create()
            $expr->fillMissing('b', 0)
                $expr->mult('a', 'c')

    ->addFunction('sale()', (string) $builder->getFunction())

// which would be equal to
    ->addFunction('sale()', 'div(sum(a,fill_missing(b,0)),add(10.5,count(mult(a,c))))')