use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.
the class AddExtraFieldsToDocument method addSdField.
private void addSdField(Search search, SDDocumentType document, SDField field, boolean validate) {
if (field.getIndexToCount() == 0 && field.getAttributes().isEmpty()) {
return;
}
for (Attribute atr : field.getAttributes().values()) {
if (atr.getName().equals(field.getName() + "_position")) {
DataType type = PositionDataType.INSTANCE;
if (atr.getCollectionType().equals(Attribute.CollectionType.ARRAY)) {
type = DataType.getArray(type);
}
addField(search, document, new SDField(document, atr.getName(), type), validate);
} else if (!atr.getName().equals(field.getName())) {
addField(search, document, new SDField(document, atr.getName(), atr.getDataType()), validate);
}
}
addField(search, document, field, validate);
}
use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.
the class SortingOperation method apply.
public void apply(SDField field) {
Attribute attribute = field.getAttributes().get(attributeName);
if (attribute == null) {
attribute = new Attribute(attributeName, field.getDataType());
field.addAttribute(attribute);
}
Sorting sorting = attribute.getSorting();
if (ascending != null) {
sorting.setAscending();
}
if (descending != null) {
sorting.setDescending();
}
if (function != null) {
sorting.setFunction(function);
}
if (strength != null) {
sorting.setStrength(strength);
}
if (locale != null) {
sorting.setLocale(locale);
}
}
use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.
the class AttributeChangeValidator method validateAttributeSettings.
private List<VespaConfigChangeAction> validateAttributeSettings() {
List<VespaConfigChangeAction> result = new ArrayList<>();
for (Attribute nextAttr : nextFields.attributes()) {
Attribute currAttr = currentFields.getAttribute(nextAttr.getName());
if (currAttr != null) {
validateAttributeSetting(currAttr, nextAttr, Attribute::isFastSearch, "fast-search", result);
validateAttributeSetting(currAttr, nextAttr, Attribute::isFastAccess, "fast-access", result);
validateAttributeSetting(currAttr, nextAttr, Attribute::isHuge, "huge", result);
validateAttributeSetting(currAttr, nextAttr, Attribute::densePostingListThreshold, "dense-posting-list-threshold", result);
validateAttributeSetting(currAttr, nextAttr, Attribute::isEnabledOnlyBitVector, "rank: filter", result);
}
}
return result;
}
use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.
the class AttributeSettingsTestCase method testAttributeSettings.
@Test
public void testAttributeSettings() throws IOException, ParseException {
Search search = SearchBuilder.buildFromFile("src/test/examples/attributesettings.sd");
SDField f1 = (SDField) search.getDocument().getField("f1");
assertTrue(f1.getAttributes().size() == 1);
Attribute a1 = f1.getAttributes().get(f1.getName());
assertThat(a1.getType(), is(Attribute.Type.LONG));
assertThat(a1.getCollectionType(), is(Attribute.CollectionType.SINGLE));
assertTrue(a1.isHuge());
assertFalse(a1.isFastSearch());
assertFalse(a1.isFastAccess());
assertFalse(a1.isRemoveIfZero());
assertFalse(a1.isCreateIfNonExistent());
SDField f2 = (SDField) search.getDocument().getField("f2");
assertTrue(f2.getAttributes().size() == 1);
Attribute a2 = f2.getAttributes().get(f2.getName());
assertThat(a2.getType(), is(Attribute.Type.LONG));
assertThat(a2.getCollectionType(), is(Attribute.CollectionType.SINGLE));
assertFalse(a2.isHuge());
assertTrue(a2.isFastSearch());
assertFalse(a2.isFastAccess());
assertFalse(a2.isRemoveIfZero());
assertFalse(a2.isCreateIfNonExistent());
assertThat(f2.getAliasToName().get("f2alias"), is("f2"));
SDField f3 = (SDField) search.getDocument().getField("f3");
assertTrue(f3.getAttributes().size() == 1);
assertThat(f3.getAliasToName().get("f3alias"), is("f3"));
Attribute a3 = f3.getAttributes().get(f3.getName());
assertThat(a3.getType(), is(Attribute.Type.LONG));
assertThat(a3.getCollectionType(), is(Attribute.CollectionType.SINGLE));
assertFalse(a3.isHuge());
assertFalse(a3.isFastSearch());
assertFalse(a3.isFastAccess());
assertFalse(a3.isRemoveIfZero());
assertFalse(a3.isCreateIfNonExistent());
assertWeightedSet(search, "f4", true, true);
assertWeightedSet(search, "f5", true, true);
assertWeightedSet(search, "f6", true, true);
assertWeightedSet(search, "f7", true, false);
assertWeightedSet(search, "f8", true, false);
assertWeightedSet(search, "f9", false, true);
assertWeightedSet(search, "f10", false, true);
}
use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.
the class AttributeSettingsTestCase method assertWeightedSet.
private void assertWeightedSet(Search search, String name, boolean createIfNonExistent, boolean removeIfZero) {
SDField f4 = (SDField) search.getDocument().getField(name);
assertTrue(f4.getAttributes().size() == 1);
Attribute a4 = f4.getAttributes().get(f4.getName());
assertThat(a4.getType(), is(Attribute.Type.STRING));
assertThat(a4.getCollectionType(), is(Attribute.CollectionType.WEIGHTEDSET));
assertFalse(a4.isHuge());
assertFalse(a4.isFastSearch());
assertFalse(a4.isFastAccess());
assertThat(removeIfZero, is(a4.isRemoveIfZero()));
assertThat(createIfNonExistent, is(a4.isCreateIfNonExistent()));
}
Aggregations