From 7d054efc1ced2c3f19c88eca4644bca06246efd4 Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Fri, 18 Mar 2022 17:34:24 +0000 Subject: [PATCH 1/6] Added unit test to replicate the issue --- .../resources/model/search-2139-model.xml | 12 ++++++++ .../search/FieldDefinitionTest.java | 28 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/e2e-test/src/main/resources/model/search-2139-model.xml b/e2e-test/src/main/resources/model/search-2139-model.xml index 76555ed20..9962ca916 100644 --- a/e2e-test/src/main/resources/model/search-2139-model.xml +++ b/e2e-test/src/main/resources/model/search-2139-model.xml @@ -126,6 +126,18 @@ true + + mltextMultiple + d:mltext + false + true + + true + false + both + true + + textPatternMany d:text diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java index bb38e667d..a6f55bddd 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java @@ -26,6 +26,9 @@ package org.alfresco.test.search.functional.searchServices.search; +import java.util.ArrayList; +import java.util.List; + import org.alfresco.rest.search.SearchResponse; import org.alfresco.utility.data.CustomObjectTypeProperties; import org.alfresco.utility.model.FileModel; @@ -61,11 +64,17 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { dataContent.usingUser(testUser).usingSite(testSite).createCustomContent(File2, "cmis:document", new CustomObjectTypeProperties()); + List mlMultipleValue = new ArrayList(); + mlMultipleValue.add("oranges"); + mlMultipleValue.add("apples"); + mlMultipleValue.add("pears"); + cmisApi.authenticateUser(testUser).usingResource(File2).addSecondaryTypes("P:allfieldtypes:text") .updateProperty("allfieldtypes:textFree", "text field definition test") .updateProperty("allfieldtypes:textPatternMany", "mltext field definition test") .updateProperty("allfieldtypes:textLOVWhole", "text field not tokenised") - .updateProperty("allfieldtypes:mltextLOVWhole", "mltext field not tokenised"); + .updateProperty("allfieldtypes:mltextLOVWhole", "mltext field not tokenised") + .updateProperty("allfieldtypes:multiplemltext", mlMultipleValue); waitForMetadataIndexing(File1.getName(), true); waitForMetadataIndexing(File2.getName(), true); @@ -198,4 +207,21 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { restClient.assertStatusCodeIs(HttpStatus.OK); Assert.assertEquals(response.getPagination().getCount(), 0); } + + // A test to test the multiple mltext field in the solr schema + @Test(priority = 8) + public void testmlTextFieldMuliple() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"oranges\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"apple\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + + response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"pear\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + } } From a3b302bb51a51b6ec13fcd74dfecd8c05cbe6a71 Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Fri, 18 Mar 2022 18:15:00 +0000 Subject: [PATCH 2/6] If PartialSolrInputDocument, merge the multiple localised values in a single array instead of doing an array of arrays which is unsupported --- .../alfresco/solr/SolrInformationServer.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index ffc3f3960..5dc1c164c 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -2321,14 +2321,24 @@ public class SolrInformationServer implements InformationServer } } - void mltextProperty(QName propertyQName, MLTextPropertyValue value, final BiConsumer valueHolder) + void mltextProperty(QName propertyQName, MLTextPropertyValue value, final BiConsumer valueHolder, boolean merge) { AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); List fields = dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields(); String storedFieldName = dataModel.getStoredMLTextField(propertyQName); - valueHolder.accept(storedFieldName, getLocalisedValues(value)); + List localisedValues = getLocalisedValues(value); + + if (merge) + { + localisedValues.forEach(val -> valueHolder.accept(storedFieldName, val)); + } + else + { + valueHolder.accept(storedFieldName, localisedValues); + } + fields.stream() .filter(FieldInstance::isSort) .forEach(field -> addMLTextProperty(valueHolder, field, value)); @@ -2406,7 +2416,7 @@ public class SolrInformationServer implements InformationServer } else if (value instanceof MLTextPropertyValue) { - mltextProperty(propertyQName,(MLTextPropertyValue) value, setAndCollect); + mltextProperty(propertyQName,(MLTextPropertyValue) value, setAndCollect, false); } else if (value instanceof ContentPropertyValue) { @@ -2431,7 +2441,8 @@ public class SolrInformationServer implements InformationServer } else if (singleValue instanceof MLTextPropertyValue) { - mltextProperty(propertyQName,(MLTextPropertyValue) singleValue, addAndCollect); + boolean merge = (document instanceof PartialSolrInputDocument); + mltextProperty(propertyQName,(MLTextPropertyValue) singleValue, addAndCollect, merge); } else if (singleValue instanceof ContentPropertyValue) { From b479fe7f89e5f7d65e80945a1e17dc0fac4ecc2a Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Fri, 18 Mar 2022 18:50:50 +0000 Subject: [PATCH 3/6] Typo in 2 of the assertions of the new test, where we do expect to find results --- .../searchServices/search/FieldDefinitionTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java index a6f55bddd..048f4cca2 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java @@ -208,7 +208,7 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { Assert.assertEquals(response.getPagination().getCount(), 0); } - // A test to test the multiple mltext field in the solr schema + // A test having multiple mltext field in the solr schema @Test(priority = 8) public void testmlTextFieldMuliple() { @@ -218,10 +218,10 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"apple\""); restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(response.getPagination().getCount(), 0); + Assert.assertEquals(response.getPagination().getCount(), 1); response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"pear\""); restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(response.getPagination().getCount(), 0); + Assert.assertEquals(response.getPagination().getCount(), 1); } } From 588ae4d6867c81fa2b3ef8d9eec5de78d705c9b1 Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Mon, 21 Mar 2022 11:37:57 +0000 Subject: [PATCH 4/6] Add comment to change in mltextProperty --- .../src/main/java/org/alfresco/solr/SolrInformationServer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index 5dc1c164c..0f9711e68 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -2330,6 +2330,9 @@ public class SolrInformationServer implements InformationServer List localisedValues = getLocalisedValues(value); + // On ML multivalued fields, we cannot add multiple arrays to the set, we need to merge the values into the + // pre-set array created by our implementation of addField on PartialSolrInputDocument. This does not apply to + // SolrInputDocument that uses the default implementation of addField. if (merge) { localisedValues.forEach(val -> valueHolder.accept(storedFieldName, val)); From da349fb0db50f1f57dac0d0f14654ed3400b2b3c Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Mon, 21 Mar 2022 11:38:45 +0000 Subject: [PATCH 5/6] Separate file with the multiple mltext property so it does not impact the other tests --- .../search/FieldDefinitionTest.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java index 048f4cca2..d5398c920 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java @@ -43,7 +43,7 @@ import org.testng.annotations.Test; */ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { - private FileModel File1, File2; + private FileModel File1, File2, File3; @BeforeClass(alwaysRun = true) public void dataPreparation() throws Exception @@ -64,20 +64,28 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { dataContent.usingUser(testUser).usingSite(testSite).createCustomContent(File2, "cmis:document", new CustomObjectTypeProperties()); + cmisApi.authenticateUser(testUser).usingResource(File2).addSecondaryTypes("P:allfieldtypes:text") + .updateProperty("allfieldtypes:textFree", "text field definition test") + .updateProperty("allfieldtypes:textPatternMany", "mltext field definition test") + .updateProperty("allfieldtypes:textLOVWhole", "text field not tokenised") + .updateProperty("allfieldtypes:mltextLOVWhole", "mltext field not tokenised"); + + File3 = new FileModel("standard-file3.txt"); + + dataContent.usingUser(testUser).usingSite(testSite).createCustomContent(File3, "cmis:document", + new CustomObjectTypeProperties()); + List mlMultipleValue = new ArrayList(); mlMultipleValue.add("oranges"); mlMultipleValue.add("apples"); mlMultipleValue.add("pears"); - cmisApi.authenticateUser(testUser).usingResource(File2).addSecondaryTypes("P:allfieldtypes:text") - .updateProperty("allfieldtypes:textFree", "text field definition test") - .updateProperty("allfieldtypes:textPatternMany", "mltext field definition test") - .updateProperty("allfieldtypes:textLOVWhole", "text field not tokenised") - .updateProperty("allfieldtypes:mltextLOVWhole", "mltext field not tokenised") - .updateProperty("allfieldtypes:multiplemltext", mlMultipleValue); - + cmisApi.authenticateUser(testUser).usingResource(File).addSecondaryTypes("P:allfieldtypes:text") + .updateProperty("allfieldtypes:multiplemltext", mlMultipleValue); + waitForMetadataIndexing(File1.getName(), true); waitForMetadataIndexing(File2.getName(), true); + waitForMetadataIndexing(File3.getName(), true); } // A test to test the text field in the solr schema, using a single word @@ -212,7 +220,7 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { @Test(priority = 8) public void testmlTextFieldMuliple() { - SearchResponse response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"oranges\""); + SearchResponse response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"orange\""); restClient.assertStatusCodeIs(HttpStatus.OK); Assert.assertEquals(response.getPagination().getCount(), 1); From 5fe9b9ee222128aff6fcafab21dc7795c5e32c7f Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Mon, 21 Mar 2022 11:58:59 +0000 Subject: [PATCH 6/6] Fixed typo in variable --- .../functional/searchServices/search/FieldDefinitionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java index d5398c920..8e36fd05d 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java @@ -80,7 +80,7 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { mlMultipleValue.add("apples"); mlMultipleValue.add("pears"); - cmisApi.authenticateUser(testUser).usingResource(File).addSecondaryTypes("P:allfieldtypes:text") + cmisApi.authenticateUser(testUser).usingResource(File3).addSecondaryTypes("P:allfieldtypes:text") .updateProperty("allfieldtypes:multiplemltext", mlMultipleValue); waitForMetadataIndexing(File1.getName(), true);