diff --git a/src/contracts/FieldType/Indexable.php b/src/contracts/FieldType/Indexable.php index 1d72714a9a..1229d34279 100644 --- a/src/contracts/FieldType/Indexable.php +++ b/src/contracts/FieldType/Indexable.php @@ -39,7 +39,7 @@ public function getIndexDefinition(); * implementation of this interface), this method is used to define default * field for matching. Default field is typically used by Field criterion. * - * @return string + * @return string|null */ public function getDefaultMatchField(); @@ -50,7 +50,7 @@ public function getDefaultMatchField(); * implementation of this interface), this method is used to define default * field for sorting. Default field is typically used by Field sort clause. * - * @return string + * @return string|null */ public function getDefaultSortField(); } diff --git a/src/lib/Search/Common/FieldNameResolver.php b/src/lib/Search/Common/FieldNameResolver.php index 02a94ab5d2..1bce132395 100644 --- a/src/lib/Search/Common/FieldNameResolver.php +++ b/src/lib/Search/Common/FieldNameResolver.php @@ -263,6 +263,12 @@ public function getIndexFieldName( $indexDefinition = $indexFieldType->getIndexDefinition(); // Should only happen by mistake, so let's throw if it does + if ($name === null) { + throw new RuntimeException( + "Undefined default sort or match field in '{$fieldTypeIdentifier}' Field Type's index definition" + ); + } + if (!isset($indexDefinition[$name])) { throw new RuntimeException( "Could not find Field '{$name}' in '{$fieldTypeIdentifier}' Field Type's index definition"