@@ -75,12 +75,15 @@ public DenseVectorFunction(ScoreScript scoreScript,
7575 }
7676 }
7777
78- if (field instanceof DenseVectorScriptDocValues ) {
78+ if (field instanceof String ) {
79+ String fieldName = (String ) field ;
80+ docValues = (DenseVectorScriptDocValues ) scoreScript .getDoc ().get (fieldName );
81+ } else if (field instanceof DenseVectorScriptDocValues ) {
7982 docValues = (DenseVectorScriptDocValues ) field ;
8083 deprecationLogger .deprecatedAndMaybeLog ("vector_function_signature" , DEPRECATION_MESSAGE );
8184 } else {
82- String fieldName = ( String ) field ;
83- docValues = ( DenseVectorScriptDocValues ) scoreScript . getDoc (). get ( fieldName );
85+ throw new IllegalArgumentException ( "For vector functions, the ' field' argument must be of type String or " +
86+ "VectorScriptDocValues" );
8487 }
8588 }
8689
@@ -230,12 +233,15 @@ public SparseVectorFunction(ScoreScript scoreScript,
230233 // Sort dimensions in the ascending order and sort values in the same order as their corresponding dimensions
231234 sortSparseDimsFloatValues (queryDims , queryValues , n );
232235
233- if (field instanceof SparseVectorScriptDocValues ) {
236+ if (field instanceof String ) {
237+ String fieldName = (String ) field ;
238+ docValues = (SparseVectorScriptDocValues ) scoreScript .getDoc ().get (fieldName );
239+ } else if (field instanceof SparseVectorScriptDocValues ) {
234240 docValues = (SparseVectorScriptDocValues ) field ;
235241 deprecationLogger .deprecatedAndMaybeLog ("vector_function_signature" , DEPRECATION_MESSAGE );
236242 } else {
237- String fieldName = ( String ) field ;
238- docValues = ( SparseVectorScriptDocValues ) scoreScript . getDoc (). get ( fieldName );
243+ throw new IllegalArgumentException ( "For vector functions, the ' field' argument must be of type String or " +
244+ "VectorScriptDocValues" );
239245 }
240246
241247 deprecationLogger .deprecatedAndMaybeLog ("sparse_vector_function" , SparseVectorFieldMapper .DEPRECATION_MESSAGE );
0 commit comments