11package io .weaviate .client6 .v1 .api .collections ;
22
3+ import java .util .ArrayList ;
4+ import java .util .Arrays ;
35import java .util .List ;
46import java .util .function .Function ;
57
@@ -17,7 +19,8 @@ public record Property(
1719 @ SerializedName ("indexSearchable" ) Boolean indexSearchable ,
1820 @ SerializedName ("tokenization" ) Tokenization tokenization ,
1921 @ SerializedName ("skipVectorization" ) Boolean skipVectorization ,
20- @ SerializedName ("vectorizePropertyName" ) Boolean vectorizePropertyName ) {
22+ @ SerializedName ("vectorizePropertyName" ) Boolean vectorizePropertyName ,
23+ @ SerializedName ("nestedProperties" ) List <Property > nestedProperties ) {
2124
2225 /**
2326 * Create a {@code text} property.
@@ -96,7 +99,7 @@ public static Property integerArray(String name, Function<Builder, ObjectBuilder
9699 }
97100
98101 /**
99- * Create a {@code bool } property.
102+ * Create a {@code blob } property.
100103 *
101104 * @param name Property name.
102105 */
@@ -267,6 +270,44 @@ public static Property numberArray(String name, Function<Builder, ObjectBuilder<
267270 return newProperty (name , DataType .NUMBER_ARRAY , fn );
268271 }
269272
273+ /**
274+ * Create a {@code object} property.
275+ *
276+ * @param name Property name.
277+ */
278+ public static Property object (String name ) {
279+ return object (name , ObjectBuilder .identity ());
280+ }
281+
282+ /**
283+ * Create a {@code object} property with additional configuration.
284+ *
285+ * @param name Property name.
286+ * @param fn Lambda expression for optional parameters.
287+ */
288+ public static Property object (String name , Function <Builder , ObjectBuilder <Property >> fn ) {
289+ return newProperty (name , DataType .OBJECT , fn );
290+ }
291+
292+ /**
293+ * Create a {@code object[]} property.
294+ *
295+ * @param name Property name.
296+ */
297+ public static Property objectArray (String name ) {
298+ return objectArray (name , ObjectBuilder .identity ());
299+ }
300+
301+ /**
302+ * Create a {@code objectArray[]} property with additional configuration.
303+ *
304+ * @param name Property name.
305+ * @param fn Lambda expression for optional parameters.
306+ */
307+ public static Property objectArray (String name , Function <Builder , ObjectBuilder <Property >> fn ) {
308+ return newProperty (name , DataType .OBJECT_ARRAY , fn );
309+ }
310+
270311 private static Property newProperty (String name , String dataType , Function <Builder , ObjectBuilder <Property >> fn ) {
271312 return fn .apply (new Builder (name , dataType )).build ();
272313 }
@@ -329,7 +370,8 @@ public Property(Builder builder) {
329370 builder .indexSearchable ,
330371 builder .tokenization ,
331372 builder .skipVectorization ,
332- builder .vectorizePropertyName );
373+ builder .vectorizePropertyName ,
374+ builder .nestedProperties .isEmpty () ? null : builder .nestedProperties );
333375 }
334376
335377 // All methods accepting a `boolean` should have a boxed overload
@@ -346,9 +388,9 @@ public Property(Builder builder) {
346388 public static class Builder implements ObjectBuilder <Property > {
347389 // Required parameters.
348390 private final String propertyName ;
391+ private final List <String > dataTypes = new ArrayList <>();
349392
350393 // Optional parameters.
351- private List <String > dataTypes ;
352394 private String description ;
353395 private Boolean indexInverted ;
354396 private Boolean indexFilterable ;
@@ -357,6 +399,7 @@ public static class Builder implements ObjectBuilder<Property> {
357399 private Tokenization tokenization ;
358400 private Boolean skipVectorization ;
359401 private Boolean vectorizePropertyName ;
402+ private List <Property > nestedProperties = new ArrayList <>();
360403
361404 /**
362405 * Create a scalar / array type property.
@@ -365,7 +408,7 @@ public static class Builder implements ObjectBuilder<Property> {
365408 */
366409 public Builder (String propertyName , String dataType ) {
367410 this .propertyName = propertyName ;
368- this .dataTypes = List . of (dataType );
411+ this .dataTypes . add (dataType );
369412 }
370413
371414 /**
@@ -375,7 +418,7 @@ public Builder(String propertyName, String dataType) {
375418 */
376419 public Builder (String propertyName , List <String > dataTypes ) {
377420 this .propertyName = propertyName ;
378- this .dataTypes = List . copyOf (dataTypes );
421+ this .dataTypes . addAll (dataTypes );
379422 }
380423
381424 /** Add property description. */
@@ -491,6 +534,32 @@ public Builder vectorizePropertyName(boolean vectorizePropertyName) {
491534 return this ;
492535 }
493536
537+ /**
538+ * Defined nested properties. This configuration is only applicable to a
539+ * property of type {@code object} and {@code object[]}.
540+ *
541+ * <pre>{@code
542+ * Property.object("address",
543+ * p -> p.nestedProperties(
544+ * Property.text("street"),
545+ * Property.integer("building_nr")))
546+ * }</pre>
547+ */
548+ public Builder nestedProperties (Property ... properties ) {
549+ return nestedProperties (Arrays .asList (properties ));
550+ }
551+
552+ /**
553+ * Defined nested properties. This configuration is only applicable to a
554+ * property of type {@code object} and {@code object[]}.
555+ *
556+ * @see Builder#nestedProperties(Property...)
557+ */
558+ public Builder nestedProperties (List <Property > properties ) {
559+ this .nestedProperties .addAll (properties );
560+ return this ;
561+ }
562+
494563 /** Convenience method to be used by {@link Property#edit}. */
495564 Builder vectorizePropertyName (Boolean vectorizePropertyName ) {
496565 this .vectorizePropertyName = vectorizePropertyName ;
0 commit comments