blob: ac4d51221efe6e52a5631a827e167a93d7a8455a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Schema;
import com.yahoo.searchdefinition.document.ImmutableImportedComplexSDField;
import com.yahoo.searchdefinition.document.ImmutableSDField;
import com.yahoo.vespa.documentmodel.SummaryField;
import com.yahoo.vespa.documentmodel.SummaryTransform;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import java.util.stream.Stream;
/**
* Adds the attribute summary transform ({@link SummaryTransform#ATTRIBUTE} to all {@link SummaryField} having an imported
* field as source.
*
* @author bjorncs
*/
public class AddAttributeTransformToSummaryOfImportedFields extends Processor {
public AddAttributeTransformToSummaryOfImportedFields(Schema schema,
DeployLogger deployLogger,
RankProfileRegistry rankProfileRegistry,
QueryProfiles queryProfiles) {
super(schema, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
schema.allImportedFields()
.forEach(field -> setTransform(field));
}
private Stream<SummaryField> getSummaryFieldsForImportedField(ImmutableSDField importedField) {
return schema.getSummaryFields(importedField).values().stream();
}
private void setTransform(ImmutableSDField field) {
if (field instanceof ImmutableImportedComplexSDField) {
getSummaryFieldsForImportedField(field).forEach(AddAttributeTransformToSummaryOfImportedFields::setAttributeCombinerTransform);
} else {
getSummaryFieldsForImportedField(field).forEach(AddAttributeTransformToSummaryOfImportedFields::setAttributeTransform);
}
}
private static void setAttributeTransform(SummaryField summaryField) {
if (summaryField.getTransform() == SummaryTransform.NONE) {
summaryField.setTransform(SummaryTransform.ATTRIBUTE);
}
}
private static void setAttributeCombinerTransform(SummaryField summaryField) {
if (summaryField.getTransform() == SummaryTransform.MATCHED_ELEMENTS_FILTER) {
summaryField.setTransform(SummaryTransform.MATCHED_ATTRIBUTE_ELEMENTS_FILTER);
} else {
summaryField.setTransform(SummaryTransform.ATTRIBUTECOMBINER);
}
}
}
|