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