Search in sources :

Example 1 with BooleanIndexDefinition

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

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

the class IndexingScriptRewriterTestCase method createPredicateField.

private static SDField createPredicateField(String name, DataType type, String script, int arity, OptionalLong lower_bound, OptionalLong upper_bound) {
    SDField field = new SDField(null, name, type);
    field.parseIndexingScript(script);
    Index index = new Index("foo");
    index.setBooleanIndexDefiniton(new BooleanIndexDefinition(OptionalInt.of(arity), lower_bound, upper_bound, OptionalDouble.empty()));
    field.addIndex(index);
    return field;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Index(com.yahoo.searchdefinition.Index) BooleanIndexDefinition(com.yahoo.searchdefinition.document.BooleanIndexDefinition)

Aggregations

Index (com.yahoo.searchdefinition.Index)2 BooleanIndexDefinition (com.yahoo.searchdefinition.document.BooleanIndexDefinition)2 SDField (com.yahoo.searchdefinition.document.SDField)2 Attribute (com.yahoo.searchdefinition.document.Attribute)1 DocumentSummary (com.yahoo.vespa.documentmodel.DocumentSummary)1 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)1