Search in sources :

Example 6 with Attribute

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);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) Attribute(com.yahoo.searchdefinition.document.Attribute) PositionDataType(com.yahoo.document.PositionDataType) DataType(com.yahoo.document.DataType)

Example 7 with Attribute

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);
    }
}
Also used : Attribute(com.yahoo.searchdefinition.document.Attribute) Sorting(com.yahoo.searchdefinition.document.Sorting)

Example 8 with Attribute

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;
}
Also used : Attribute(com.yahoo.searchdefinition.document.Attribute) ArrayList(java.util.ArrayList) VespaConfigChangeAction(com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction)

Example 9 with Attribute

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);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) Test(org.junit.Test)

Example 10 with Attribute

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()));
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute)

Aggregations

Attribute (com.yahoo.searchdefinition.document.Attribute)22 SDField (com.yahoo.searchdefinition.document.SDField)11 Test (org.junit.Test)4 DocumentSummary (com.yahoo.vespa.documentmodel.DocumentSummary)3 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)3 DataType (com.yahoo.document.DataType)2 Field (com.yahoo.document.Field)2 Index (com.yahoo.searchdefinition.Index)2 Search (com.yahoo.searchdefinition.Search)2 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ArrayDataType (com.yahoo.document.ArrayDataType)1 PositionDataType (com.yahoo.document.PositionDataType)1 TensorDataType (com.yahoo.document.TensorDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)1 BooleanIndexDefinition (com.yahoo.searchdefinition.document.BooleanIndexDefinition)1 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)1 Ranking (com.yahoo.searchdefinition.document.Ranking)1