diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java index 636aa2bef..6c50f39e2 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java @@ -776,29 +776,34 @@ public class AlfrescoSolrDataModel implements QueryConstants } } + // TODO: make it better private void addHighlightSearchFields( PropertyDefinition propertyDefinition , IndexedField indexedField) { - FieldInstance field = new FieldInstance("text@s_stored@" + propertyDefinition.getName(), false, false); - indexedField.getFields().add(field); - /* - if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.TRUE) - || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH)) + QName propertyDataTypeQName = propertyDefinition.getDataType().getName(); + StringBuilder builder = + new StringBuilder() + .append(propertyDataTypeQName.getLocalName()) + .append("@"); + + if(propertyDataTypeQName.equals(DataTypeDefinition.MLTEXT)) { - if(crossLocaleSearchDataTypes.contains(propertyDefinition.getDataType().getName()) || crossLocaleSearchProperties.contains(propertyDefinition.getName())) - { - indexedField.addField(getFieldForText(false, true, false, propertyDefinition), false, false); - indexedField.addField(getFieldForText(true, true, false, propertyDefinition), false, false); - } - else - { - indexedField.addField(getFieldForText(true, true, false, propertyDefinition), false, false); - } + builder.append('m'); + } + else if(propertyDataTypeQName.equals(DataTypeDefinition.CONTENT)) + { + builder.append('s'); } else { - indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false); + builder.append(propertyDefinition.isMultiValued() ? "m" : "s"); } - */ + + builder.append("_stored_lt@").append(propertyDefinition.getName().toString()); + + System.out.println(propertyDefinition.getName() + " has been mapped to " + builder); + + FieldInstance field = new FieldInstance(builder.toString(), true, false); + indexedField.getFields().add(field); } /* 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 3d1ff1155..448cd0a37 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 @@ -2193,6 +2193,67 @@ public class SolrInformationServer implements InformationServer "FIELD: Name = " + field.getField() + ", Localised = " + field.localised + ", Sort = " + field.sort; } + static void mltextProperty(QName propertyQName, MLTextPropertyValue value, final BiConsumer valueHolder) + { + AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); + List fields = dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields(); + + // TODO: is there a better way to determine if the field is a mltext or not + // (for example) a boolean or a primitive (the default model always associates 1 field to such types) + // Boolean properties (like isIndexed) are caught in this loop because they are classified as StringPropertyValue + if (fields.size() > 1) { + + // TODO: this should be got from AlfrescoSolrDataModel + String storedFieldName = "mltext@m_stored_lt@" + propertyQName; + + valueHolder.accept(storedFieldName, getLocalisedValues(value)); + + // mltext Sort fields concatenate multiple values (1 locale - 1 value) in a single string + // we cannot do that using copyfield or update request processor so the only possible approach + // is to send the sort field separately (like we do for doc values "text" fields) + fields.stream() + .filter(FieldInstance::isSort) + .forEach(field -> addMLTextProperty(valueHolder, field, value)); + + } else { + // Theoretically we should never be in this branch (primitive types are not mltext) + dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() + .forEach(field -> addMLTextProperty(valueHolder, field, value)); + } + } + + static void stringProperty(QName propertyQName, StringPropertyValue value, PropertyValue locale, final BiConsumer valueHolder) + { + AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); + List fields = dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields(); + + // TODO: is there a better way to determine if the field is a text/mltext/content or not + // (for example) a boolean or a primitive (the default model always associates 1 field to such types) + // Boolean properties (like isIndexed) are caught in this loop because they are classified as StringPropertyValue + if (fields.size() > 1) { + + // TODO: this should be got from AlfrescoSolrDataModel + String storedFieldName = "text@s_stored_lt@" + propertyQName; + + valueHolder.accept(storedFieldName, getLocalisedValue((StringPropertyValue) value, locale)); + + /* the schema have been changed so all the stored field above is copied on every text@...@ fields + The only exception is the text@sd___@ which has docvalues enabled. We can't copy the stored field + there because the locale prefix cannot be removed (as it happens with the other non-localised text@ fields) + */ + + dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() + .stream() + .filter(field -> field.getField().startsWith("text@sd___@")) + .forEach(field -> addStringProperty(valueHolder, field, (StringPropertyValue) value, locale)); + } else { + +// OLD CODE: this relates to primitive/non-text fields/properties (like LID, APATH or boolean@...) + dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() + .forEach(field -> addStringProperty(valueHolder, field, (StringPropertyValue) value, locale)); + } + } + static void populateProperties( Map properties, boolean contentIndexingHasBeenRequestedForThisNode, @@ -2211,6 +2272,8 @@ public class SolrInformationServer implements InformationServer final BiConsumer setValue = document::setField; final BiConsumer addValue = document::addField; final BiConsumer collectName = (name, value) -> addFieldIfNotSet(document, name); + final BiConsumer setAndCollect = setValue.andThen(collectName); + final BiConsumer addAndCollect = addValue.andThen(collectName); for (Entry property : properties.entrySet()) { @@ -2221,54 +2284,22 @@ public class SolrInformationServer implements InformationServer PropertyValue value = property.getValue(); if(value != null) { - AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); - if (value instanceof StringPropertyValue) { - /* - * - * Boolean properties (like isIndexed) are classified are StringPropertyValue - */ - List fields = dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields(); - if (fields.size() > 1) { - System.out.println(propertyQName + "=>" + dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields().size()); - String storedFieldName = "text@s_stored@" + propertyQName; - System.out.println(storedFieldName); - - document.setField(storedFieldName, getLocalisedValue((StringPropertyValue) value, properties)); - /* the schema have been changed so all the stored field above is copied on every text@...@ fields - The only exception is the text@sd___@ which has docvalues enabled. We can't copy the stored field - there because the locale prefix cannot be removed (as it happens with the other non-localised text@ fields) - */ - - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - .filter(field -> field.getField().startsWith("text@sd___@")) - .forEach(field -> addStringProperty(setValue.andThen(collectName), field, (StringPropertyValue) value, properties)); - } else { - -// OLD CODE - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - //.peek(field -> System.out.println(propertyToString(document.get("DBID"), "Single StringPropertyValue", propertyQName, value, field))) - .forEach(field -> addStringProperty(setValue.andThen(collectName), field, (StringPropertyValue) value, properties)); - } + stringProperty(propertyQName, (StringPropertyValue) value, properties.get(ContentModel.PROP_LOCALE), setAndCollect); } else if (value instanceof MLTextPropertyValue) { - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - //.peek(field -> System.out.println(propertyToString(document.get("id"), "Single MLTextPropertyValue", propertyQName, value, field))) - .forEach(field -> addMLTextProperty(setValue.andThen(collectName), field, (MLTextPropertyValue) value)); + mltextProperty(propertyQName,(MLTextPropertyValue) value, setAndCollect); } else if (value instanceof ContentPropertyValue) { - addContentProperty(setValue.andThen(collectName), document, propertyQName, (ContentPropertyValue) value, contentIndexingIsEnabled); - + addContentProperty(setAndCollect, document, propertyQName, (ContentPropertyValue) value, contentIndexingIsEnabled); } else if (value instanceof MultiPropertyValue) { MultiPropertyValue typedValue = (MultiPropertyValue) value; + AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); clearFields( document, dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() @@ -2280,20 +2311,15 @@ public class SolrInformationServer implements InformationServer { if (singleValue instanceof StringPropertyValue) { - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - .peek(field -> System.out.println(propertyToString(document.get("DBID"), "Multiple StringPropertyValue", propertyQName, value, field))) - .forEach(field -> addStringProperty(addValue.andThen(collectName), field, (StringPropertyValue) singleValue, properties)); + stringProperty(propertyQName, (StringPropertyValue) singleValue, properties.get(ContentModel.PROP_LOCALE), addAndCollect); } else if (singleValue instanceof MLTextPropertyValue) { - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - .peek(field -> System.out.println(propertyToString(document.get("DBID"), "Multiple MLTextPropertyValue", propertyQName, value, field))) .forEach(field -> addMLTextProperty(addValue.andThen(collectName), field, (MLTextPropertyValue) singleValue)); + mltextProperty(propertyQName,(MLTextPropertyValue) singleValue, addAndCollect); } else if (singleValue instanceof ContentPropertyValue) { - addContentProperty(addValue.andThen(collectName), document, propertyQName, (ContentPropertyValue) singleValue, contentIndexingIsEnabled); + addContentProperty(addAndCollect, document, propertyQName, (ContentPropertyValue) singleValue, contentIndexingIsEnabled); } } } @@ -2630,18 +2656,37 @@ public class SolrInformationServer implements InformationServer this.getTrackerStats().addDocTransformationTime(System.nanoTime() - start); - dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() - .stream() - .peek(field -> doc.removeField(field.getField())) - .forEach(field -> { - doc.addField( - field.getField(), - field.isLocalised() - ? "\u0000" + locale + "\u0000" + textContent - : textContent); + // TODO: The field name should be retrieved from AlfrescoSolrDataModel + String storedField = "content@s_stored_lt@" + propertyQName; - addFieldIfNotSet(doc, field.getField()); - }); + doc.setField(storedField, "\u0000" + locale + "\u0000" + textContent); + + dataModel.getIndexedFieldNamesForProperty(propertyQName) + .getFields() + .forEach(field -> addFieldIfNotSet(doc, field.getField())); + } + + private static List getLocalisedValues(MLTextPropertyValue mlTextPropertyValue) + { + if (mlTextPropertyValue == null) + { + return Collections.emptyList(); + } + + List values = new ArrayList<>(); + for (Locale locale : mlTextPropertyValue.getLocales()) + { + final String propValue = mlTextPropertyValue.getValue(locale); + if((locale == null) || propValue == null) + { + continue; + } + + StringBuilder builder = new StringBuilder(propValue.length() + 16); + builder.append("\u0000").append(locale.toString()).append("\u0000").append(propValue); + values.add(builder.toString()); + } + return values; } private static void addMLTextProperty(BiConsumer consumer, FieldInstance field, MLTextPropertyValue mlTextPropertyValue) @@ -3820,10 +3865,10 @@ public class SolrInformationServer implements InformationServer } } - private static String getLocalisedValue(StringPropertyValue property, Map properties) + private static String getLocalisedValue(StringPropertyValue property, PropertyValue localeProperty) { Locale locale = - ofNullable(properties.get(ContentModel.PROP_LOCALE)) + ofNullable(localeProperty) .map(StringPropertyValue.class::cast) .map(StringPropertyValue::getValue) .map(value -> DefaultTypeConverter.INSTANCE.convert(Locale.class, value)) @@ -3832,23 +3877,9 @@ public class SolrInformationServer implements InformationServer return "\u0000" + locale.toString() + "\u0000" + property.getValue(); } - private static void addStringProperty(BiConsumer consumer, FieldInstance field, StringPropertyValue property, Map properties) + private static void addStringProperty(BiConsumer consumer, FieldInstance field, StringPropertyValue property, PropertyValue localeProperty) { - if(field.isLocalised()) - { - Locale locale = - ofNullable(properties.get(ContentModel.PROP_LOCALE)) - .map(StringPropertyValue.class::cast) - .map(StringPropertyValue::getValue) - .map(value -> DefaultTypeConverter.INSTANCE.convert(Locale.class, value)) - .orElse(I18NUtil.getLocale()); - - consumer.accept(field.getField(), "\u0000" + locale.toString() + "\u0000" + property.getValue()); - } - else - { - consumer.accept(field.getField(), property.getValue()); - } + consumer.accept(field.getField(), field.isLocalised() ? getLocalisedValue(property, localeProperty) : property.getValue()); } private static void addFieldIfNotSet(SolrInputDocument doc, String name) diff --git a/search-services/alfresco-search/src/main/java/org/apache/solr/handler/component/AlfrescoSolrHighlighter.java b/search-services/alfresco-search/src/main/java/org/apache/solr/handler/component/AlfrescoSolrHighlighter.java index 1d97bdfba..348fb6be9 100644 --- a/search-services/alfresco-search/src/main/java/org/apache/solr/handler/component/AlfrescoSolrHighlighter.java +++ b/search-services/alfresco-search/src/main/java/org/apache/solr/handler/component/AlfrescoSolrHighlighter.java @@ -241,6 +241,7 @@ public class AlfrescoSolrHighlighter extends DefaultSolrHighlighter implements P // Additional mappings coming from this 2nd round Map additionalMappings = new HashMap<>(); + /* identifiers.keySet() .forEach(id -> { final NamedList docHighlighting = (NamedList) highlightingResponse.get(id); @@ -257,7 +258,8 @@ public class AlfrescoSolrHighlighter extends DefaultSolrHighlighter implements P mappings.putAll(additionalMappings); withDebug(mappings); - +*/ +/* // We are going to re-call the highlight for those documents/fields which didnt' produce any result in the // previous step. In order to do that we need // - a (Solr) field name: the second-level choice coming from Alfresco Data Model @@ -295,6 +297,8 @@ public class AlfrescoSolrHighlighter extends DefaultSolrHighlighter implements P .filter(notNullAndNotEmpty) .collect(toList()); + + // Combine (actually reduce) the highlight response coming from the first try, with each // partial highlight response coming from subsequent calls NamedList responseBeforeRenamingFields = partialHighlightingResponses.stream() @@ -315,9 +319,10 @@ public class AlfrescoSolrHighlighter extends DefaultSolrHighlighter implements P }); return accumulator; }); +*/ - - // Final step: under each document section, highlight snippets are associated with Solr field names, + NamedList responseBeforeRenamingFields = highlightingResponse; + // Final step: under each document section, highlight snippets are associated with Solr field names, // so we need to replace them with fields actually requested // In addition, beside the snippets we want to have the document DBID as well. NamedList response = new SimpleOrderedMap<>(); diff --git a/search-services/alfresco-search/src/main/resources/solr/instance/templates/rerank/conf/schema.xml b/search-services/alfresco-search/src/main/resources/solr/instance/templates/rerank/conf/schema.xml index 61b599dc0..f8cddffe2 100644 --- a/search-services/alfresco-search/src/main/resources/solr/instance/templates/rerank/conf/schema.xml +++ b/search-services/alfresco-search/src/main/resources/solr/instance/templates/rerank/conf/schema.xml @@ -18,431 +18,431 @@ 1.6: useDocValuesAsStored defaults to true. --> - - - + + + - - + + - - - - - - - - - + + + + + + + + + - - - - - - + + + + + + - + - - + + - - + + - - - + + + - - + + - - + + - - + + - + - - - - - - - + + + + + + + - - - + + + - - - + + + - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - + + + + + - - + + - - - - - - - - - + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - + NOTE: If you want to optimize search for precision, use default operator AND in your query + parser config with further down in this file. Use + OR if you would like to optimize for recall (default). + --> + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id \ No newline at end of file diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java index 800901791..c53a5e764 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java @@ -219,7 +219,7 @@ public class AlfrescoSolrUtils nodeMetaData.setAncestors(ancestors); Map props = new HashMap<>(); props.put(ContentModel.PROP_IS_INDEXED, new StringPropertyValue("true")); - props.put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.US, 0l, "UTF-8", "text/plain", null)); + props.put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.US, 0L, "UTF-8", "text/plain", null)); nodeMetaData.setProperties(props); //If create createError is true then we leave out the nodeRef which will cause an error if(!createError) { diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java index 2f5fde335..16417ee15 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java @@ -70,7 +70,7 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT List> data = asList( of(NAME_METADATA_ATTRIBUTE, "some very long name", - DESCRIPTION_METADATA_ATTRIBUTE, "mydesc", + DESCRIPTION_METADATA_ATTRIBUTE, "is this a long description? No, I do not think is so long", TITLE_METADATA_ATTRIBUTE, "title1 is very long"), of(NAME_METADATA_ATTRIBUTE, long_text, TITLE_METADATA_ATTRIBUTE, "title2"), @@ -180,7 +180,7 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT SolrServletRequest req = areq(params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", - HighlightParams.FIELDS, "content,name,title", + HighlightParams.FIELDS, "content,name,title,description", HighlightParams.SNIPPETS, "4", HighlightParams.FRAGSIZE, "40"), "{" + @@ -190,12 +190,14 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", - "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very long name']", - "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very long']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some long text. It has the']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word long in many places. In fact, it has']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' long on some different fragments. Let us']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to long in this case.']"); + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='this is some long text. It has the']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.=' word long in many places. In fact, it has']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.=' long on some different fragments. Let us']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.=' see what happens to long in this case.']", + "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='some very long name']", + "//lst[@name='highlighting']/lst[2]/arr[@name='description']/str[.='is this a long description? No, I do']", + "//lst[@name='highlighting']/lst[2]/arr[@name='description']/str[.=' not think is so long']", + "//lst[@name='highlighting']/lst[2]/arr[@name='title']/str[.='title1 is very long']"); } @Test @@ -246,8 +248,8 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=2]", - "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very {long} name']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some {long}']"); + "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='some very {long} name']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='this is some {long}']"); } @Test @@ -288,13 +290,13 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT assertQ(req, "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=2]", "*[count(//lst[@name='highlighting']/lst/str[@name='DBID'])=2]", - "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very [long] name']", - "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very (long)']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some [long] text. It has the word [long] in many places. In fact, it has [long] on some']"); + "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='some very [long] name']", + "//lst[@name='highlighting']/lst[2]/arr[@name='title']/str[.='title1 is very (long)']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='this is some [long] text. It has the word [long] in many places. In fact, it has [long] on some']"); } @Test - public void highlightingRequiredFieldsTest() + public void highlightingRequiredFields() { SolrServletRequest req = areq(params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", @@ -307,7 +309,7 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='title'])=1]", - "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very {long}']"); + "//lst[@name='highlighting']/lst[2]/arr[@name='title']/str[.='title1 is very {long}']"); req = areq(params("q", "name:long OR title:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", @@ -322,7 +324,7 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='title'])=1]", "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=0]", - "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very {long}']"); + "//lst[@name='highlighting']/lst[2]/arr[@name='title']/str[.='title1 is very {long}']"); } @Test @@ -330,7 +332,7 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT { SolrServletRequest req = areq(params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", - HighlightParams.Q, "long", + HighlightParams.Q, "world", HighlightParams.FIELDS, "content,name,title", HighlightParams.SIMPLE_PRE, "", HighlightParams.SIMPLE_POST, "", @@ -340,12 +342,11 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", - "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very long name']", - "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very long']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some long text. It has the']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word long in many places. In fact, it has']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' long on some different fragments. Let us']", - "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to long in this case.']"); + "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='some very long name']", + "//lst[@name='highlighting']/lst[2]/arr[@name='title']/str[.='title1 is very long']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='this is some long text']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='. It has the word long in many places. In fact, it has long']", + "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.=' on some different fragments. Let us see what happens to long in this case.']"); } @Test @@ -373,7 +374,6 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT { SolrServletRequest req = areq(params("q", "name:plural", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", - //HighlightParams.Q, "lon*", HighlightParams.FIELDS, NAME_METADATA_ATTRIBUTE, HighlightParams.HIGHLIGHT_MULTI_TERM, "false", HighlightParams.SIMPLE_PRE, "{", diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/MultiPropertyValue.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/MultiPropertyValue.java index ff167a6ee..7575672c4 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/MultiPropertyValue.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/MultiPropertyValue.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Solr Client - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Solr Client + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.solr.client; import java.util.ArrayList; @@ -35,17 +35,15 @@ import java.util.List; */ public class MultiPropertyValue extends PropertyValue { - private List values; + private final List values; public MultiPropertyValue() { - super(); - this.values = new ArrayList(10); + this.values = new ArrayList<>(); } public MultiPropertyValue(List values) { - super(); this.values = values; } @@ -64,4 +62,4 @@ public class MultiPropertyValue extends PropertyValue { return "MultiPropertyValue [values=" + values + "]"; } -} +} \ No newline at end of file