The following example illustrates accessing data held in a weighted set.
Note that the Data Access API doesn't have a "set" or "weighted set" concept;
the weighted set is represented as an unordered array of objects
where each object has an "item" and a "weight" field.
The weight is a long integer value,
while the item type will vary according to the field type as declared in the schema.
<field name="alias">title: James Bond[89], title: Bond[15]</field>
Unit testing with structured data
For unit testing it is useful to be able to create structured data fields programmatically.
This case be done using Slime:
importcom.yahoo.slime.*;importcom.yahoo.data.access.slime.SlimeAdapter;// Struct example:Slimeslime=newSlime();Cursorstruct=slime.setObject();struct.setString("foo","bar");struct.setDouble("number",1.0);myHit.setField("mystruct",newSlimeAdapter(struct));// Array example:Slimeslime=newSlime();Cursorarray=slime.setArray();array.addString("foo");array.addString("bar");myHit.setField("myarray",newSlimeAdapter(array));// Arrays and objects can be arbitrarily nested// Alternatively, create the slime structure from a JSON string:Slimeslime=SlimeUtils.jsonToSlime(myJsonString.getBytes(StandardCharsets.UTF_8));myHit.setField("myfield",newSlimeAdapter(slime.get()));