Search in sources :

Example 66 with SDField

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

the class IndexingValidation method process.

@Override
public void process(boolean validate) {
    if (!validate)
        return;
    VerificationContext context = new VerificationContext(new MyAdapter(search));
    for (SDField field : search.allConcreteFields()) {
        ScriptExpression script = field.getIndexingScript();
        try {
            script.verify(context);
            MyConverter converter = new MyConverter();
            for (StatementExpression exp : script) {
                // TODO: stop doing this explicitly when visiting a script does not branch
                converter.convert(exp);
            }
        } catch (VerificationException e) {
            fail(search, field, "For expression '" + e.getExpression() + "': " + e.getMessage());
        }
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField)

Example 67 with SDField

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

the class IntegerIndex2Attribute method process.

@Override
public void process(boolean validate) {
    for (SDField field : search.allConcreteFields()) {
        if (field.doesIndexing() && field.getDataType().getPrimitiveType() instanceof NumericDataType) {
            if (field.getIndex(field.getName()) != null && !(field.getIndex(field.getName()).getType().equals(Index.Type.VESPA)))
                continue;
            ScriptExpression script = field.getIndexingScript();
            Set<String> attributeNames = new HashSet<>();
            new MyVisitor(attributeNames).visit(script);
            field.setIndexingScript((ScriptExpression) new MyConverter(attributeNames).convert(script));
            warn(search, field, "Changed to attribute because numerical indexes (field has type " + field.getDataType().getName() + ") is not currently supported." + " Index-only settings may fail. Ignore this warning for streaming search.");
        }
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) NumericDataType(com.yahoo.document.NumericDataType) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) HashSet(java.util.HashSet)

Example 68 with SDField

use of com.yahoo.searchdefinition.document.SDField 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 69 with SDField

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

the class CreatePositionZCurve method process.

@Override
public void process(boolean validate) {
    for (SDField field : search.allConcreteFields()) {
        DataType fieldType = field.getDataType();
        if (!isSupportedPositionType(fieldType))
            continue;
        if (validate && field.doesIndexing()) {
            fail(search, field, "Indexing of data type '" + fieldType.getName() + "' is not supported, " + "replace 'index' statement with 'attribute'.");
        }
        if (!field.doesAttributing())
            continue;
        boolean doesSummary = field.doesSummarying();
        String fieldName = field.getName();
        field.getAttributes().remove(fieldName);
        String zName = PositionDataType.getZCurveFieldName(fieldName);
        SDField zCurveField = createZCurveField(field, zName, validate);
        search.addExtraField(zCurveField);
        search.fieldSets().addBuiltInFieldSetItem(BuiltInFieldSets.INTERNAL_FIELDSET_NAME, zCurveField.getName());
        // configure summary
        Collection<String> summaryTo = removeSummaryTo(field);
        ensureCompatibleSummary(field, zName, PositionDataType.getPositionSummaryFieldName(fieldName), // will become "xmlstring"
        DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, summaryTo, validate);
        ensureCompatibleSummary(field, zName, PositionDataType.getDistanceSummaryFieldName(fieldName), DataType.INT, SummaryTransform.DISTANCE, summaryTo, validate);
        // clear indexing script
        field.setIndexingScript(null);
        SDField posX = field.getStructField(PositionDataType.FIELD_X);
        if (posX != null) {
            posX.setIndexingScript(null);
        }
        SDField posY = field.getStructField(PositionDataType.FIELD_Y);
        if (posY != null) {
            posY.setIndexingScript(null);
        }
        if (doesSummary)
            ensureCompatibleSummary(field, zName, field.getName(), field.getDataType(), SummaryTransform.GEOPOS, summaryTo, validate);
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) PositionDataType(com.yahoo.document.PositionDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 70 with SDField

use of com.yahoo.searchdefinition.document.SDField 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)

Aggregations

SDField (com.yahoo.searchdefinition.document.SDField)85 Test (org.junit.Test)33 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)22 Search (com.yahoo.searchdefinition.Search)15 Attribute (com.yahoo.searchdefinition.document.Attribute)11 Index (com.yahoo.searchdefinition.Index)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 ArrayList (java.util.ArrayList)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 Field (com.yahoo.document.Field)6 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)6 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)5 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)5 ArrayDataType (com.yahoo.document.ArrayDataType)4 DataType (com.yahoo.document.DataType)4 DocumentReference (com.yahoo.searchdefinition.DocumentReference)4 RankProfile (com.yahoo.searchdefinition.RankProfile)4 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4