Search in sources :

Example 1 with Attribute

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

the class DocumentModelBuilder method addToModel.

public void addToModel(Search search) {
    // Then we add the search specific stuff
    SearchDef searchDef = new SearchDef(search.getName());
    addSearchFields(search.extraFieldList(), searchDef);
    for (Field f : search.getDocument().fieldSet()) {
        addSearchField((SDField) f, searchDef);
    }
    for (SDField field : search.allConcreteFields()) {
        for (Attribute attribute : field.getAttributes().values()) {
            if (!searchDef.getFields().containsKey(attribute.getName())) {
                searchDef.add(new SearchField(new Field(attribute.getName(), field), !field.getIndices().isEmpty(), true));
            }
        }
    }
    for (Field f : search.getDocument().fieldSet()) {
        addAlias((SDField) f, searchDef);
    }
    model.getSearchManager().add(searchDef);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SearchField(com.yahoo.vespa.documentmodel.SearchField) Field(com.yahoo.document.Field) SearchDef(com.yahoo.vespa.documentmodel.SearchDef) SearchField(com.yahoo.vespa.documentmodel.SearchField) SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 2 with Attribute

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

the class TypedTransformProvider method requiresTransform.

@Override
protected final boolean requiresTransform(Expression exp) {
    if (exp instanceof OutputExpression) {
        String fieldName = ((OutputExpression) exp).getFieldName();
        if (exp instanceof AttributeExpression) {
            Attribute attribute = search.getAttribute(fieldName);
            if (attribute == null)
                throw new IllegalArgumentException("Attribute '" + fieldName + "' not found.");
            fieldType = attribute.getDataType();
        } else if (exp instanceof IndexExpression) {
            Field field = search.getConcreteField(fieldName);
            if (field == null)
                throw new IllegalArgumentException("Index field '" + fieldName + "' not found.");
            fieldType = field.getDataType();
        } else if (exp instanceof SummaryExpression) {
            Field field = search.getSummaryField(fieldName);
            if (field == null)
                throw new IllegalArgumentException("Summary field '" + fieldName + "' not found.");
            fieldType = field.getDataType();
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return requiresTransform(exp, fieldType);
}
Also used : Field(com.yahoo.document.Field) Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 3 with Attribute

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

the class PredicateProcessor method process.

@Override
public void process(boolean validate) {
    for (SDField field : search.allConcreteFields()) {
        if (field.getDataType() == DataType.PREDICATE) {
            if (validate && field.doesIndexing()) {
                fail(search, field, "Use 'attribute' instead of 'index'. This will require a refeed if you have upgraded.");
            }
            if (field.doesAttributing()) {
                Attribute attribute = field.getAttributes().get(field.getName());
                for (Index index : field.getIndices().values()) {
                    BooleanIndexDefinition booleanDefinition = index.getBooleanIndexDefiniton();
                    if (validate && (booleanDefinition == null || !booleanDefinition.hasArity())) {
                        fail(search, field, "Missing arity value in predicate field.");
                    }
                    if (validate && (booleanDefinition.getArity() < 2)) {
                        fail(search, field, "Invalid arity value in predicate field, must be greater than 1.");
                    }
                    double threshold = booleanDefinition.getDensePostingListThreshold();
                    if (validate && (threshold <= 0 || threshold > 1)) {
                        fail(search, field, "Invalid dense-posting-list-threshold value in predicate field. " + "Value must be in range (0..1].");
                    }
                    attribute.setArity(booleanDefinition.getArity());
                    attribute.setLowerBound(booleanDefinition.getLowerBound());
                    attribute.setUpperBound(booleanDefinition.getUpperBound());
                    attribute.setDensePostingListThreshold(threshold);
                    addPredicateOptimizationIlScript(field, booleanDefinition);
                }
                DocumentSummary summary = search.getSummary("attributeprefetch");
                if (summary != null) {
                    summary.remove(attribute.getName());
                }
                for (SummaryField summaryField : search.getSummaryFields(field).values()) {
                    summaryField.setTransform(SummaryTransform.NONE);
                }
            }
        } else if (validate && field.getDataType().getPrimitiveType() == DataType.PREDICATE) {
            fail(search, field, "Collections of predicates are not allowed.");
        } else if (validate && field.getDataType() == DataType.RAW && field.doesIndexing()) {
            fail(search, field, "Indexing of RAW fields is not supported.");
        } else if (validate) {
            // if field is not a predicate, disallow predicate-related index parameters
            for (Index index : field.getIndices().values()) {
                if (index.getBooleanIndexDefiniton() != null) {
                    BooleanIndexDefinition def = index.getBooleanIndexDefiniton();
                    if (def.hasArity()) {
                        fail(search, field, "Arity parameter is used only for predicate type fields.");
                    } else if (def.hasLowerBound() || def.hasUpperBound()) {
                        fail(search, field, "Parameters lower-bound and upper-bound are used only for predicate type fields.");
                    } else if (def.hasDensePostingListThreshold()) {
                        fail(search, field, "Parameter dense-posting-list-threshold is used only for predicate type fields.");
                    }
                }
            }
        }
    }
}
Also used : SummaryField(com.yahoo.vespa.documentmodel.SummaryField) SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) Index(com.yahoo.searchdefinition.Index) DocumentSummary(com.yahoo.vespa.documentmodel.DocumentSummary) BooleanIndexDefinition(com.yahoo.searchdefinition.document.BooleanIndexDefinition)

Example 4 with Attribute

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

the class SummaryConsistency method makeAttributeTransformIfAppropriate.

/**
 * If the source is an attribute, make this use the attribute transform
 */
private void makeAttributeTransformIfAppropriate(SummaryField summaryField, Search search) {
    if (summaryField.getTransform() != SummaryTransform.NONE)
        return;
    Attribute attribute = search.getAttribute(summaryField.getSingleSource());
    if (attribute == null)
        return;
    summaryField.setTransform(SummaryTransform.ATTRIBUTE);
}
Also used : Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 5 with Attribute

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

the class AttributeOperation method apply.

public void apply(SDField field) {
    Attribute attribute = field.getAttributes().get(name);
    if (attribute == null) {
        attribute = new Attribute(name, field.getDataType());
        field.addAttribute(attribute);
    }
    if (huge != null) {
        attribute.setHuge(huge);
    }
    if (fastSearch != null) {
        attribute.setFastSearch(fastSearch);
    }
    if (fastAccess != null) {
        attribute.setFastAccess(fastAccess);
    }
    if (prefetch != null) {
        attribute.setPrefetch(prefetch);
    }
    if (enableBitVectors != null) {
        attribute.setEnableBitVectors(enableBitVectors);
    }
    if (enableOnlyBitVector != null) {
        attribute.setEnableOnlyBitVector(enableOnlyBitVector);
    }
    if (doAlias) {
        field.getAliasToName().put(alias, aliasedName);
    }
    if (tensorType.isPresent()) {
        attribute.setTensorType(tensorType.get());
    }
}
Also used : 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