mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-09-10 14:11:25 +00:00
Merge pull request #1417 from Alfresco/fix/MNT-22159_mltext_multiple_index
MNT-22159 Multiple ML text field fails to index
This commit is contained in:
@@ -126,6 +126,18 @@
|
||||
<facetable>true</facetable>
|
||||
</index>
|
||||
</property>
|
||||
<property name="allfieldtypes:multiplemltext">
|
||||
<title>mltextMultiple</title>
|
||||
<type>d:mltext</type>
|
||||
<mandatory>false</mandatory>
|
||||
<multiple>true</multiple>
|
||||
<index enabled="true">
|
||||
<atomic>true</atomic>
|
||||
<stored>false</stored>
|
||||
<tokenised>both</tokenised>
|
||||
<facetable>true</facetable>
|
||||
</index>
|
||||
</property>
|
||||
<property name="allfieldtypes:textPatternMany">
|
||||
<title>textPatternMany</title>
|
||||
<type>d:text</type>
|
||||
|
@@ -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<String> mlMultipleValue = new ArrayList<String>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -2321,14 +2321,27 @@ public class SolrInformationServer implements InformationServer
|
||||
}
|
||||
}
|
||||
|
||||
void mltextProperty(QName propertyQName, MLTextPropertyValue value, final BiConsumer<String, Object> valueHolder)
|
||||
void mltextProperty(QName propertyQName, MLTextPropertyValue value, final BiConsumer<String, Object> valueHolder, boolean merge)
|
||||
{
|
||||
AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
|
||||
List<FieldInstance> fields = dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields();
|
||||
|
||||
String storedFieldName = dataModel.getStoredMLTextField(propertyQName);
|
||||
|
||||
valueHolder.accept(storedFieldName, getLocalisedValues(value));
|
||||
List<String> 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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user