summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/processing
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-12-04 12:49:27 +0000
committerTor Egge <tegge@oath.com>2018-12-06 11:00:34 +0000
commit467b2e387ada478e06a568be7a92cbf5228f6a48 (patch)
treef5c64895b06d1a26e4eb990d3c81418363e02f68 /config-model/src/test/java/com/yahoo/searchdefinition/processing
parent51d5defd8116fadb68b1a3f9367cdb5c2cb6d845 (diff)
Process position summary entries.
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition/processing')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java244
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java46
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java62
3 files changed, 311 insertions, 41 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java
new file mode 100644
index 00000000000..00df42d60c3
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java
@@ -0,0 +1,244 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition.processing;
+
+import com.google.common.collect.ImmutableMap;
+import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.config.model.test.MockApplicationPackage;
+import com.yahoo.document.DataType;
+import com.yahoo.document.PositionDataType;
+import com.yahoo.document.ReferenceDataType;
+import com.yahoo.document.TemporaryStructuredDataType;
+import com.yahoo.searchdefinition.DocumentReference;
+import com.yahoo.searchdefinition.DocumentReferences;
+import com.yahoo.searchdefinition.Search;
+import com.yahoo.searchdefinition.document.SDDocumentType;
+import com.yahoo.searchdefinition.document.SDField;
+import com.yahoo.searchdefinition.document.TemporaryImportedField;
+import com.yahoo.searchdefinition.document.TemporarySDField;
+import com.yahoo.vespa.documentmodel.DocumentSummary;
+import com.yahoo.vespa.documentmodel.SummaryField;
+import com.yahoo.vespa.documentmodel.SummaryTransform;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class AdjustPositionSummaryFieldsTestCase {
+
+ @Test
+ public void test_pos_summary() {
+ SearchModel model = new SearchModel(false);
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos");
+ model.resolve();
+ model.assertSummaryField("my_pos", PositionDataType.INSTANCE, SummaryTransform.GEOPOS, "pos_zcurve");
+ model.assertSummaryField("my_pos.position", DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, "pos_zcurve");
+ model.assertSummaryField("my_pos.distance", DataType.INT, SummaryTransform.DISTANCE, "pos_zcurve");
+ }
+
+ @Test
+ public void test_imported_pos_summary() {
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.resolve();
+ model.assertSummaryField("my_pos", PositionDataType.INSTANCE, SummaryTransform.GEOPOS, "my_pos_zcurve");
+ model.assertSummaryField("my_pos.position", DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, "my_pos_zcurve");
+ model.assertSummaryField("my_pos.distance", DataType.INT, SummaryTransform.DISTANCE, "my_pos_zcurve");
+ }
+
+ @Test
+ public void test_imported_pos_summary_bad_source() {
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos");
+ model.resolve();
+ model.assertSummaryField("my_pos", PositionDataType.INSTANCE, SummaryTransform.NONE, "pos");
+ model.assertNoSummaryField("my_pos.position");
+ model.assertNoSummaryField("my_pos.distance");
+ }
+
+ @Test
+ public void test_imported_pos_summary_bad_datatype() {
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", DataType.getArray(PositionDataType.INSTANCE), null, "pos");
+ model.resolve();
+ model.assertSummaryField("my_pos", DataType.getArray(PositionDataType.INSTANCE), SummaryTransform.NONE, "pos");
+ model.assertNoSummaryField("my_pos.position");
+ model.assertNoSummaryField("my_pos.distance");
+ }
+
+ @Rule
+ public final ExpectedException exceptionRule = ExpectedException.none();
+
+ @Test
+ public void test_pos_summary_no_attr() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos': "
+ + "No position attribute 'pos_zcurve'");
+ SearchModel model = new SearchModel(false, false, false);
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos");
+ model.resolve();
+ }
+
+ @Test
+ public void test_pos_summary_bad_attr() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos': "
+ + "No position attribute 'pos_zcurve'");
+ SearchModel model = new SearchModel(false, false, true);
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos");
+ model.resolve();
+ }
+
+ @Test
+ public void test_imported_pos_summary_no_attr() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', import field 'my_pos_zcurve': "
+ + "Field 'pos_zcurve' via reference field 'ref': Not found");
+ SearchModel model = new SearchModel(true, false, false);
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.resolve();
+ }
+
+ @Test
+ public void test_imported_pos_summary_bad_attr() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos': "
+ + "No position attribute 'my_pos_zcurve'");
+ SearchModel model = new SearchModel(true, false, true);
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.resolve();
+ }
+
+ @Test
+ public void test_my_pos_position_summary_bad_datatype() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos.position': "
+ + "exists with type 'datatype string (code: 2)', should be of type 'datatype Array<string> (code: -1486737430)");
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.addSummaryField("my_pos.position", DataType.STRING, null, "pos");
+ model.resolve();
+ }
+
+ @Test
+ public void test_my_pos_position_summary_bad_transform() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos.position': "
+ + "has summary transform 'none', should have transform 'positions'");
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), null, "pos");
+ model.resolve();
+ }
+
+ @Test
+ public void test_my_pos_position_summary_bad_source() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For search 'child', field 'my_pos.position': "
+ + "has source '[source field 'pos']', should have source 'source field 'my_pos_zcurve''");
+ SearchModel model = new SearchModel();
+ model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null);
+ model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, "pos");
+ model.resolve();
+ }
+
+ static class SearchModel extends ParentChildSearchModel {
+
+ public SearchModel() {
+ this(true);
+ }
+
+ public SearchModel(boolean importedPos) {
+ this(importedPos, true, false);
+ }
+
+ public SearchModel(boolean importedPos, boolean setupPosAttr, boolean setupBadAttr) {
+ super();
+ if (importedPos) {
+ createPositionField(parentSearch, setupPosAttr, setupBadAttr);
+ }
+ addRefField(childSearch, parentSearch, "ref");
+ if (importedPos) {
+ addImportedField("my_pos", "ref", "pos");
+ } else {
+ createPositionField(childSearch, setupPosAttr, setupBadAttr);
+ }
+ }
+
+ private void createPositionField(Search search, boolean setupPosAttr, boolean setupBadAttr) {
+ String ilScript = setupPosAttr ? "{ summary | attribute }" : "{ summary }";
+ search.getDocument().addField(createField("pos", PositionDataType.INSTANCE, ilScript));
+ if (setupBadAttr) {
+ search.getDocument().addField(createField("pos_zcurve", DataType.LONG, "{ attribute }"));
+ }
+ }
+
+ public void addSummaryField(String fieldName, DataType dataType, SummaryTransform transform, String source) {
+ addSummaryField("my_summary", fieldName, dataType, transform, source);
+ }
+
+ public void addSummaryField(String summaryName, String fieldName, DataType dataType, SummaryTransform transform, String source) {
+ DocumentSummary summary = childSearch.getSummary(summaryName);
+ if (summary == null) {
+ summary = new DocumentSummary(summaryName);
+ childSearch.addSummary(summary);
+ }
+ SummaryField summaryField = new SummaryField(fieldName, dataType);
+ if (source != null) {
+ summaryField.addSource(source);
+ }
+ if (transform != null) {
+ summaryField.setTransform(transform);
+ }
+ summary.add(summaryField);
+ }
+
+ public void assertNoSummaryField(String fieldName) {
+ assertNoSummaryField("my_summary", fieldName);
+ }
+
+ public void assertNoSummaryField(String summaryName, String fieldName) {
+ DocumentSummary summary = childSearch.getSummary(summaryName);
+ assertNotNull(summary);
+ SummaryField summaryField = summary.getSummaryField(fieldName);
+ assertNull(summaryField);
+ }
+
+ public void assertSummaryField(String fieldName, DataType dataType, SummaryTransform transform, String source) {
+ assertSummaryField("my_summary", fieldName, dataType, transform, source);
+ }
+
+ public void assertSummaryField(String summaryName, String fieldName, DataType dataType, SummaryTransform transform, String source) {
+ DocumentSummary summary = childSearch.getSummary(summaryName);
+ assertNotNull(summary);
+ SummaryField summaryField = summary.getSummaryField(fieldName);
+ assertNotNull(summaryField);
+ assertEquals(dataType, summaryField.getDataType());
+ assertEquals(transform, summaryField.getTransform());
+ if (source == null) {
+ assertEquals(0, summaryField.getSourceCount());
+ } else {
+ assertEquals(1, summaryField.getSourceCount());
+ assertEquals(source, summaryField.getSingleSource());
+ }
+ }
+
+ public void resolve() {
+ resolve(parentSearch);
+ resolve(childSearch);
+ }
+
+ private static void resolve(Search search) {
+ new CreatePositionZCurve(search, null, null, null).process(true, false);
+ assertNotNull(search.temporaryImportedFields().get());
+ assertFalse(search.importedFields().isPresent());
+ new ImportedFieldsResolver(search, null, null, null).process(true, false);
+ assertFalse(search.temporaryImportedFields().isPresent());
+ assertNotNull(search.importedFields().get());
+ new AdjustPositionSummaryFields(search, null, null, null).process(true, false);
+ }
+ }
+}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
index de08bf66548..3e3cd932e55 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
@@ -112,19 +112,16 @@ public class ImportedFieldsResolverTestCase {
new SearchModel().addImportedField("my_predicate_field", "ref", "predicate_field").resolve();
}
- static class SearchModel {
+ static class SearchModel extends ParentChildSearchModel {
- private final ApplicationPackage app = MockApplicationPackage.createEmpty();
public final Search grandParentSearch;
- public final Search parentSearch;
- public final Search childSearch;
public ImportedFields importedFields;
public SearchModel() {
+ super();
grandParentSearch = createSearch("grandparent");
grandParentSearch.getDocument().addField(createField("ancient_field", DataType.INT, "{ attribute }"));
- parentSearch = createSearch("parent");
parentSearch.getDocument().addField(createField("attribute_field", DataType.INT, "{ attribute }"));
parentSearch.getDocument().addField(createField("attribute_and_index", DataType.INT, "{ attribute | index }"));
parentSearch.getDocument().addField(new TemporarySDField("not_attribute", DataType.INT));
@@ -133,49 +130,16 @@ public class ImportedFieldsResolverTestCase {
addRefField(parentSearch, grandParentSearch, "ref");
addImportedField(parentSearch, "ancient_field", "ref", "ancient_field");
- childSearch = createSearch("child");
addRefField(childSearch, parentSearch, "ref");
}
- private Search createSearch(String name) {
- Search result = new Search(name, app);
- result.addDocument(new SDDocumentType(name));
- return result;
- }
-
- private static TemporarySDField createField(String name, DataType dataType, String indexingScript) {
- TemporarySDField result = new TemporarySDField(name, dataType);
- result.parseIndexingScript(indexingScript);
- return result;
- }
-
- private static SDField createRefField(String parentType, String fieldName) {
- return new TemporarySDField(fieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(parentType)));
- }
- private static void addRefField(Search child, Search parent, String fieldName) {
- SDField refField = createRefField(parent.getName(), fieldName);
- child.getDocument().addField(refField);
- child.getDocument().setDocumentReferences(new DocumentReferences(ImmutableMap.of(refField.getName(),
- new DocumentReference(refField, parent))));
- }
-
- public SearchModel addImportedField(String fieldName, String referenceFieldName, String targetFieldName) {
+ protected SearchModel addImportedField(String fieldName, String referenceFieldName, String targetFieldName) {
return addImportedField(childSearch, fieldName, referenceFieldName, targetFieldName);
}
- private SearchModel addImportedField(Search search, String fieldName, String referenceFieldName, String targetFieldName) {
- search.temporaryImportedFields().get().add(new TemporaryImportedField(fieldName, referenceFieldName, targetFieldName));
- return this;
- }
-
- public SearchModel addSummaryField(String fieldName, DataType dataType) {
- DocumentSummary summary = childSearch.getSummary("my_summary");
- if (summary == null) {
- summary = new DocumentSummary("my_summary");
- childSearch.addSummary(summary);
- }
- summary.add(new SummaryField(fieldName, dataType));
+ protected SearchModel addImportedField(Search search, String fieldName, String referenceFieldName, String targetFieldName) {
+ super.addImportedField(search, fieldName, referenceFieldName, targetFieldName);
return this;
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java
new file mode 100644
index 00000000000..7d6a8507dd3
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java
@@ -0,0 +1,62 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition.processing;
+
+import com.google.common.collect.ImmutableMap;
+import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.config.model.test.MockApplicationPackage;
+import com.yahoo.document.DataType;
+import com.yahoo.document.ReferenceDataType;
+import com.yahoo.document.TemporaryStructuredDataType;
+import com.yahoo.searchdefinition.DocumentReference;
+import com.yahoo.searchdefinition.DocumentReferences;
+import com.yahoo.searchdefinition.Search;
+import com.yahoo.searchdefinition.document.SDDocumentType;
+import com.yahoo.searchdefinition.document.SDField;
+import com.yahoo.searchdefinition.document.TemporaryImportedField;
+import com.yahoo.searchdefinition.document.TemporarySDField;
+
+/*
+ * Fixture class used for ImportedFieldsResolverTestCase and AdjustPositionSummaryFieldsTestCase.
+ */
+public class ParentChildSearchModel {
+ private final ApplicationPackage app = MockApplicationPackage.createEmpty();
+ public Search parentSearch;
+ public Search childSearch;
+
+ ParentChildSearchModel() {
+ parentSearch = createSearch("parent");
+ childSearch = createSearch("child");
+ }
+
+ protected Search createSearch(String name) {
+ Search result = new Search(name, app);
+ result.addDocument(new SDDocumentType(name));
+ return result;
+ }
+
+ protected static TemporarySDField createField(String name, DataType dataType, String indexingScript) {
+ TemporarySDField result = new TemporarySDField(name, dataType);
+ result.parseIndexingScript(indexingScript);
+ return result;
+ }
+
+ protected static SDField createRefField(String parentType, String fieldName) {
+ return new TemporarySDField(fieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(parentType)));
+ }
+
+ protected static void addRefField(Search child, Search parent, String fieldName) {
+ SDField refField = createRefField(parent.getName(), fieldName);
+ child.getDocument().addField(refField);
+ child.getDocument().setDocumentReferences(new DocumentReferences(ImmutableMap.of(refField.getName(),
+ new DocumentReference(refField, parent))));
+ }
+
+ protected ParentChildSearchModel addImportedField(String fieldName, String referenceFieldName, String targetFieldName) {
+ return addImportedField(childSearch, fieldName, referenceFieldName, targetFieldName);
+ }
+
+ protected ParentChildSearchModel addImportedField(Search search, String fieldName, String referenceFieldName, String targetFieldName) {
+ search.temporaryImportedFields().get().add(new TemporaryImportedField(fieldName, referenceFieldName, targetFieldName));
+ return this;
+ }
+}