diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-10-28 09:12:32 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-10-28 09:15:49 +0100 |
commit | 6e2cf6330c05859672cd9e72ef0c667215969bb3 (patch) | |
tree | 99d6fa1ad4407dd76616136f4ac96ba848401ec5 /config-model | |
parent | a92f65c46645fca9040dcfc3b0fbda0386ae7f60 (diff) |
Use attribute combiner summary transform when source field is a complex
struct field with only attributes.
Diffstat (limited to 'config-model')
2 files changed, 57 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/SummaryConsistency.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/SummaryConsistency.java index d2c4968ca26..a4ad3964d47 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/SummaryConsistency.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/SummaryConsistency.java @@ -8,11 +8,14 @@ import com.yahoo.searchdefinition.RankProfileRegistry; import com.yahoo.searchdefinition.document.Attribute; import com.yahoo.document.WeightedSetDataType; import com.yahoo.searchdefinition.Search; +import com.yahoo.searchdefinition.document.ImmutableSDField; import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; import com.yahoo.vespa.model.container.search.QueryProfiles; +import static com.yahoo.searchdefinition.document.ComplexAttributeFieldUtils.isComplexFieldWithOnlyStructFieldAttributes; + /** * Ensure that summary field transforms for fields having the same name * are consistent across summary classes @@ -33,6 +36,7 @@ public class SummaryConsistency extends Processor { for (SummaryField summaryField : summary.getSummaryFields() ) { assertConsistency(summaryField, search, validate); makeAttributeTransformIfAppropriate(summaryField, search); + makeAttributeCombinerTransformIfAppropriate(summaryField, search); } } } @@ -63,6 +67,17 @@ public class SummaryConsistency extends Processor { summaryField.setTransform(SummaryTransform.ATTRIBUTE); } + /** If the source is a complex field with only struct field attributes then make this use the attribute combiner transform */ + private void makeAttributeCombinerTransformIfAppropriate(SummaryField summaryField,Search search) { + if (summaryField.getTransform() == SummaryTransform.NONE) { + String source_field_name = summaryField.getSingleSource(); + ImmutableSDField source = search.getField(source_field_name); + if (source != null && isComplexFieldWithOnlyStructFieldAttributes(source)) { + summaryField.setTransform(SummaryTransform.ATTRIBUTECOMBINER); + } + } + } + private void assertConsistentTypes(SummaryField existing, SummaryField seen) { if (existing.getDataType() instanceof WeightedSetDataType && seen.getDataType() instanceof WeightedSetDataType && ((WeightedSetDataType)existing.getDataType()).getNestedType().equals(((WeightedSetDataType)seen.getDataType()).getNestedType())) diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/SummaryConsistencyTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/SummaryConsistencyTestCase.java new file mode 100644 index 00000000000..41b3028e06c --- /dev/null +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/SummaryConsistencyTestCase.java @@ -0,0 +1,42 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.processing; + +import com.yahoo.searchdefinition.Search; +import com.yahoo.searchdefinition.SearchBuilder; +import com.yahoo.searchdefinition.parser.ParseException; +import com.yahoo.vespa.documentmodel.SummaryTransform; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SummaryConsistencyTestCase { + + @Test + public void attribute_combiner_transform_is_set_when_source_is_array_of_struct_with_only_struct_field_attributes() throws ParseException { + String sd = "search structmemorysummary {\n" + + " document structmemorysummary {\n" + + " struct elem {\n" + + " field name type string {}\n" + + " field weight type int {}\n" + + " }\n" + + " field elem_array type array<elem> {\n" + + " indexing: summary\n" + + " struct-field name {\n" + + " indexing: attribute\n" + + " }\n" + + " struct-field weight {\n" + + " indexing: attribute\n" + + " }\n" + + " }\n" + + " }\n" + + " document-summary unfiltered {\n" + + " summary elem_array_unfiltered type array<elem> {\n" + + " source: elem_array\n" + + " }\n" + + " }\n" + + "\n" + + "}"; + Search search = SearchBuilder.createFromString(sd).getSearch(); + assertEquals(SummaryTransform.ATTRIBUTECOMBINER, search.getSummaryField("elem_array_unfiltered").getTransform()); + } +} |