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());
}
}
}
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.");
}
}
}
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);
}
}
}
}
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);
}
}
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;
}
Aggregations