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..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
@@ -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;
@@ -40,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
@@ -66,9 +69,23 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest {
.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(File3).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
@@ -198,4 +215,21 @@ public class FieldDefinitionTest extends AbstractSearchServicesE2ETest {
restClient.assertStatusCodeIs(HttpStatus.OK);
Assert.assertEquals(response.getPagination().getCount(), 0);
}
+
+ // A test having multiple mltext field in the solr schema
+ @Test(priority = 8)
+ public void testmlTextFieldMuliple()
+ {
+ SearchResponse response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"orange\"");
+ 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(), 1);
+
+ response = queryAsUser(testUser, "allfieldtypes_multiplemltext:\"pear\"");
+ restClient.assertStatusCodeIs(HttpStatus.OK);
+ Assert.assertEquals(response.getPagination().getCount(), 1);
+ }
}
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..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
@@ -2321,14 +2321,27 @@ 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);
+
+ // 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));
+ }
+ else
+ {
+ valueHolder.accept(storedFieldName, localisedValues);
+ }
+
fields.stream()
.filter(FieldInstance::isSort)
.forEach(field -> addMLTextProperty(valueHolder, field, value));
@@ -2406,7 +2419,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 +2444,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)
{