Search in sources :

Example 16 with Attribute

use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.

the class ImplicitSummaries method collectSummaries.

private void collectSummaries(SDField field, Search search, boolean validate) {
    SummaryField addedSummaryField = null;
    // Implicit
    String fieldName = field.getName();
    SummaryField fieldSummaryField = field.getSummaryField(fieldName);
    if (fieldSummaryField == null && field.doesSummarying()) {
        fieldSummaryField = new SummaryField(fieldName, field.getDataType());
        fieldSummaryField.setImplicit(true);
        addSummaryFieldSources(fieldSummaryField, field);
        fieldSummaryField.addDestination("default");
        field.addSummaryField(fieldSummaryField);
        addedSummaryField = fieldSummaryField;
    }
    if (fieldSummaryField != null) {
        for (String dest : fieldSummaryField.getDestinations()) {
            DocumentSummary summary = search.getSummary(dest);
            if (summary != null) {
                summary.add(fieldSummaryField);
            }
        }
    }
    // Attribute prefetch
    for (Attribute attribute : field.getAttributes().values()) {
        if (attribute.getName().equals(fieldName)) {
            if (addedSummaryField != null) {
                addedSummaryField.setTransform(SummaryTransform.ATTRIBUTE);
            }
            if (attribute.isPrefetch()) {
                addPrefetchAttribute(attribute, field, search);
            }
        }
    }
    // Position attributes
    if (field.doesSummarying()) {
        for (Attribute attribute : field.getAttributes().values()) {
            if (!attribute.isPosition())
                continue;
            DocumentSummary attributePrefetchSummary = getOrCreateAttributePrefetchSummary(search);
            attributePrefetchSummary.add(field.getSummaryField(PositionDataType.getDistanceSummaryFieldName(fieldName)));
            attributePrefetchSummary.add(field.getSummaryField(PositionDataType.getPositionSummaryFieldName(fieldName)));
        }
    }
    // Explicits
    for (SummaryField summaryField : field.getSummaryFields()) {
        // Make sure we fetch from attribute here too
        Attribute attribute = field.getAttributes().get(fieldName);
        if (attribute != null && summaryField.getTransform() == SummaryTransform.NONE) {
            summaryField.setTransform(SummaryTransform.ATTRIBUTE);
        }
        if (isValid(summaryField, search, validate)) {
            addToDestinations(summaryField, search);
        }
    }
}
Also used : SummaryField(com.yahoo.vespa.documentmodel.SummaryField) Attribute(com.yahoo.searchdefinition.document.Attribute) DocumentSummary(com.yahoo.vespa.documentmodel.DocumentSummary)

Example 17 with Attribute

use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.

the class MakeAliases method process.

@Override
public void process(boolean validate) {
    List<String> usedAliases = new ArrayList<>();
    for (SDField field : search.allConcreteFields()) {
        for (Map.Entry<String, String> e : field.getAliasToName().entrySet()) {
            String alias = e.getKey();
            String name = e.getValue();
            String errMsg = "For search '" + search.getName() + "': alias '" + alias + "' ";
            if (validate && search.existsIndex(alias)) {
                throw new IllegalArgumentException(errMsg + "is illegal since it is the name of an index.");
            }
            if (validate && search.getAttribute(alias) != null) {
                throw new IllegalArgumentException(errMsg + "is illegal since it is the name of an attribute.");
            }
            if (validate && usedAliases.contains(alias)) {
                throw new IllegalArgumentException(errMsg + "specified more than once.");
            }
            usedAliases.add(alias);
            Index index = field.getIndex(name);
            Attribute attribute = field.getAttributes().get(name);
            if (index != null) {
                // alias will be for index in this case, since it is the one used in a search
                index.addAlias(alias);
            } else if (attribute != null && !field.doesIndexing()) {
                attribute.getAliases().add(alias);
            } else {
                index = new Index(name);
                index.addAlias(alias);
                field.addIndex(index);
            }
        }
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) ArrayList(java.util.ArrayList) Index(com.yahoo.searchdefinition.Index) Map(java.util.Map)

Example 18 with Attribute

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

Example 19 with Attribute

use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.

the class CreatePositionZCurve method createZCurveField.

private SDField createZCurveField(SDField inputField, String fieldName, boolean validate) {
    if (validate && search.getConcreteField(fieldName) != null || search.getAttribute(fieldName) != null) {
        throw newProcessException(search, null, "Incompatible position attribute '" + fieldName + "' already created.");
    }
    boolean isArray = inputField.getDataType() instanceof ArrayDataType;
    SDField field = new SDField(fieldName, isArray ? DataType.getArray(DataType.LONG) : DataType.LONG);
    Attribute attribute = new Attribute(fieldName, Attribute.Type.LONG, isArray ? Attribute.CollectionType.ARRAY : Attribute.CollectionType.SINGLE);
    attribute.setPosition(true);
    attribute.setFastSearch(true);
    field.addAttribute(attribute);
    ScriptExpression script = inputField.getIndexingScript();
    script = (ScriptExpression) new RemoveSummary(inputField.getName()).convert(script);
    script = (ScriptExpression) new PerformZCurve(field, fieldName).convert(script);
    field.setIndexingScript(script);
    return field;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) ArrayDataType(com.yahoo.document.ArrayDataType) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)

Example 20 with Attribute

use of com.yahoo.searchdefinition.document.Attribute in project vespa by vespa-engine.

the class RankProfileTypeSettingsProcessor method processImportedField.

private void processImportedField(ImportedField field) {
    SDField targetField = field.targetField();
    Attribute attribute = targetField.getAttributes().get(targetField.getName());
    if (attribute != null && attribute.tensorType().isPresent()) {
        addAttributeTypeToRankProfiles(field.fieldName(), attribute.tensorType().get().toString());
    }
}
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