From 206efbe6dbe848923a929a8980abb001bb1cd4ff Mon Sep 17 00:00:00 2001 From: Bertrand Gorge Date: Wed, 24 Jun 2026 14:35:20 +0200 Subject: [PATCH] Fixed issue #86 - dont sort on keyword for dates and numerical values --- src/QueryEngine/Sort/PropertySort.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/QueryEngine/Sort/PropertySort.php b/src/QueryEngine/Sort/PropertySort.php index afb0f91..ba6270e 100644 --- a/src/QueryEngine/Sort/PropertySort.php +++ b/src/QueryEngine/Sort/PropertySort.php @@ -67,7 +67,12 @@ public function toQuery(): BuilderInterface { $parameters['mode'] = $this->mode; } - $field = $this->field->hasKeywordSubfield() ? + // Numeric and date fields must sort on the base field (numField/datField), + // not on the .keyword subfield (which is text and gives alphanumeric order). + $fieldType = $this->field->getPropertyFieldType(); + $isNumericType = ( $fieldType === 'num' || $fieldType === 'dat' ); + + $field = ( !$isNumericType && $this->field->hasKeywordSubfield() ) ? $this->field->getKeywordField() : $this->field->getPropertyField();