SqlOrder class makes custom elasticsearch sort orders non-trivial to implement

Xon

Well-known member
Affected version
2.3.8
I'm not sure if this is an XF or XFES bug report, but the issue straddles both of them.

AbstractData::getTypeOrder() is type hinted as mixed but the ConversationMessage search handler has the return type of ?SqlOrder, and then various parts of the Query class & call tree reference string|SqlOrder as the type.

Except XFES uses FunctionOrder in places, so the typing on Query::getOrder() is inaccurate. The tricky bit is being able to reliably extend search handlers which have getTypeOrder() type hinted as ?SqlOrder.

Simply subclassing SqlOrder doesn't work, as getSqlResults blindly fetches the getOrder() and inserts it into an order-by clause like so:
PHP:
$order = $query->getOrder();
if ($order instanceof Query\SqlOrder)
{
    $tables += $order->getTables();
    $orderByClause = 'ORDER BY ' . $order->getOrder() . ', search_index.hit_position ASC';
}
else
{
    $orderByClause = 'ORDER BY search_index.hit_position ASC';
}

While SqlOrder->order is hinted as being a string; none of the code paths getting or setting have a type argument/return type of string. Perhaps this should return an array and then the calling code assembles that into an SQL order-by clause allowing for getOrder() to return an empty array.
 
Back
Top Bottom