use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.
the class ToWsetTestCase method assertConvert.
private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero));
FieldValue val = ctx.getValue();
assertEquals(WeightedSet.class, val.getClass());
WeightedSet wset = (WeightedSet) val;
WeightedSetDataType type = wset.getDataType();
assertEquals(DataType.STRING, type.getNestedType());
assertEquals(createIfNonExistent, type.createIfNonExistent());
assertEquals(removeIfZero, type.removeIfZero());
assertEquals(1, wset.size());
assertEquals(Integer.valueOf(1), wset.get(new StringFieldValue("69")));
}
use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.
the class DocumentGenTest method testLocalApp.
@Test
public void testLocalApp() throws MojoFailureException {
DocumentGenMojo mojo = new DocumentGenMojo();
mojo.execute(new File("etc/localapp/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
Map<String, Search> searches = mojo.getSearches();
assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
assertTrue(searches.get("book").getDocument("book").getField("mywsfloat").getDataType() instanceof WeightedSetDataType);
assertTrue(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsfloat").getDataType())).getNestedType() == DataType.FLOAT);
}
use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.
the class MapValueUpdate method applyTo.
@Override
public FieldValue applyTo(FieldValue fval) {
if (fval instanceof Array) {
Array array = (Array) fval;
FieldValue element = array.getFieldValue(((IntegerFieldValue) value).getInteger());
element = update.applyTo(element);
array.set(((IntegerFieldValue) value).getInteger(), element);
} else if (fval instanceof WeightedSet) {
WeightedSet wset = (WeightedSet) fval;
WeightedSetDataType wtype = wset.getDataType();
Integer weight = wset.get(value);
if (weight == null) {
if (wtype.createIfNonExistent() && update instanceof ArithmeticValueUpdate) {
weight = 0;
} else {
return fval;
}
}
weight = (Integer) update.applyTo(new IntegerFieldValue(weight)).getWrappedValue();
wset.put(value, weight);
if (wtype.removeIfZero() && update instanceof ArithmeticValueUpdate && weight == 0) {
wset.remove(value);
}
}
return fval;
}
use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.
the class ArraysWeightedSetsTestCase method testArrayWeightedSetsImporting.
@Test
public void testArrayWeightedSetsImporting() throws java.io.IOException, com.yahoo.searchdefinition.parser.ParseException {
Search search = SearchBuilder.buildFromFile("src/test/examples/arraysweightedsets.sd");
SDField tags = (SDField) search.getDocument().getField("tags");
assertTrue(tags.getDataType() instanceof ArrayDataType);
assertEquals(DataType.STRING, ((CollectionDataType) tags.getDataType()).getNestedType());
SDField ratings = (SDField) search.getDocument().getField("ratings");
assertTrue(ratings.getDataType() instanceof ArrayDataType);
assertEquals(DataType.INT, ((CollectionDataType) ratings.getDataType()).getNestedType());
SDField flags = (SDField) search.getDocument().getField("flags");
assertTrue(flags.getDataType() instanceof WeightedSetDataType);
assertEquals(DataType.STRING, ((CollectionDataType) flags.getDataType()).getNestedType());
SDField banners = (SDField) search.getDocument().getField("banners");
assertTrue(banners.getDataType() instanceof WeightedSetDataType);
assertEquals(DataType.INT, ((CollectionDataType) banners.getDataType()).getNestedType());
}
use of com.yahoo.document.WeightedSetDataType in project vespa by vespa-engine.
the class WeightedSetOperation method apply.
public void apply(SDField field) {
WeightedSetDataType ctype = (WeightedSetDataType) field.getDataType();
if (createIfNonExistent != null) {
field.setDataType(DataType.getWeightedSet(ctype.getNestedType(), createIfNonExistent, ctype.removeIfZero()));
}
ctype = (WeightedSetDataType) field.getDataType();
if (removeIfZero != null) {
field.setDataType(DataType.getWeightedSet(ctype.getNestedType(), ctype.createIfNonExistent(), removeIfZero));
}
ctype = (WeightedSetDataType) field.getDataType();
for (Object o : field.getAttributes().values()) {
Attribute attribute = (Attribute) o;
attribute.setRemoveIfZero(ctype.removeIfZero());
attribute.setCreateIfNonExistent(ctype.createIfNonExistent());
}
}
Aggregations