mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
[SEARCH-2166]
changes for making work date derived fields in search and fl statement
This commit is contained in:
+38
-8
@@ -108,6 +108,12 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_DAY_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_HOUR_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MINUTE_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MONTH_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_SECOND_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_YEAR_FIELD_SUFFIX;
|
||||
|
||||
/**
|
||||
* @author Andy
|
||||
@@ -1027,6 +1033,12 @@ public class AlfrescoSolrDataModel implements QueryConstants
|
||||
|
||||
}
|
||||
|
||||
public String getDateDerivedFIeld(QName propertyQName)
|
||||
{
|
||||
PropertyDefinition propertyDefinition = getPropertyDefinition(propertyQName);
|
||||
return "part@sd@" + propertyDefinition.getName().toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all the field names into which we must copy the source data
|
||||
@@ -1626,28 +1638,46 @@ public class AlfrescoSolrDataModel implements QueryConstants
|
||||
}
|
||||
}
|
||||
|
||||
if (propertyDef == null || propertyDef.getName() == null){
|
||||
if (propertyDef == null || propertyDef.getName() == null)
|
||||
{
|
||||
return mapNonPropertyFields(luceneField);
|
||||
}
|
||||
|
||||
if (propertyDef.getName().equals(DataTypeDefinition.TEXT))
|
||||
if ((propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME)
|
||||
|| propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE) &&
|
||||
!isDerivedDateField(fieldNameAndEnding.getSecond())))
|
||||
{
|
||||
return getStoredTextField(propertyDef.getName());
|
||||
return getDateDerivedFIeld(propertyDef.getName()) + fieldNameAndEnding.getSecond();
|
||||
}
|
||||
else if (propertyDef.getName().equals(DataTypeDefinition.MLTEXT))
|
||||
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))
|
||||
{
|
||||
return getStoredMLTextField(propertyDef.getName());
|
||||
return getStoredTextField(propertyDef.getName()) + fieldNameAndEnding.getSecond();
|
||||
}
|
||||
else if (propertyDef.getName().equals(DataTypeDefinition.CONTENT))
|
||||
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
|
||||
{
|
||||
return getStoredContentField(propertyDef.getName());
|
||||
return getStoredMLTextField(propertyDef.getName()) + fieldNameAndEnding.getSecond();
|
||||
}
|
||||
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
return getStoredContentField(propertyDef.getName()) + fieldNameAndEnding.getSecond();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef);
|
||||
return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef)
|
||||
+ fieldNameAndEnding.getSecond();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDerivedDateField(String suffix) {
|
||||
return Set.of(UNIT_OF_TIME_YEAR_FIELD_SUFFIX,
|
||||
UNIT_OF_TIME_MONTH_FIELD_SUFFIX,
|
||||
UNIT_OF_TIME_DAY_FIELD_SUFFIX,
|
||||
UNIT_OF_TIME_HOUR_FIELD_SUFFIX,
|
||||
UNIT_OF_TIME_MINUTE_FIELD_SUFFIX,
|
||||
UNIT_OF_TIME_SECOND_FIELD_SUFFIX).contains(suffix);
|
||||
}
|
||||
|
||||
|
||||
public String mapProperty(String potentialProperty, FieldUse fieldUse, SolrQueryRequest req, int position)
|
||||
{
|
||||
if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_"))
|
||||
|
||||
+10
-8
@@ -18,10 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.solr.component;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
|
||||
import org.alfresco.solr.AlfrescoSolrDataModel;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.common.params.SolrParams;
|
||||
import org.apache.solr.handler.component.ResponseBuilder;
|
||||
@@ -35,13 +32,17 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
|
||||
/**
|
||||
* @Author elia
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transform the fieldlist depending on the use of cached transformer:
|
||||
* [cached] -> add to the field list the translations of the fiels to the internal schema notation
|
||||
* otherwise -> modify the field list in order to contains a subset of the following fields:
|
||||
* id, DBID, _version_ and score
|
||||
*
|
||||
* @author eporciani
|
||||
*/
|
||||
public class RewriteFieldListComponent extends SearchComponent {
|
||||
|
||||
@@ -85,7 +86,7 @@ public class RewriteFieldListComponent extends SearchComponent {
|
||||
fieldListSet.addAll(defaultNonCachedFields);
|
||||
}
|
||||
|
||||
params.set(CommonParams.FL, String.join(",", fieldListSet));
|
||||
params.set("fl", String.join(",", fieldListSet));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,7 +97,8 @@ public class RewriteFieldListComponent extends SearchComponent {
|
||||
else
|
||||
{
|
||||
fieldListSet.addAll(solrReturnFields.getLuceneFieldNames().stream()
|
||||
.map( field -> AlfrescoSolrDataModel.getInstance().mapStoredProperty(field, req))
|
||||
.map( field -> AlfrescoSolrDataModel.getInstance()
|
||||
.mapStoredProperty(field, req))
|
||||
.filter(Objects::nonNull)
|
||||
.map(schemaFieldName -> schemaFieldName.chars()
|
||||
.mapToObj(c -> (char) c)
|
||||
@@ -106,7 +108,7 @@ public class RewriteFieldListComponent extends SearchComponent {
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
params.add(CommonParams.FL, String.join(",", fieldListSet));
|
||||
params.add("fl", String.join(",", fieldListSet));
|
||||
}
|
||||
|
||||
// This is added for filtering the fields in the cached transformer.
|
||||
|
||||
+11
@@ -4217,6 +4217,17 @@ public class Solr4QueryParser extends QueryParser implements QueryConstants
|
||||
}
|
||||
|
||||
}
|
||||
else if (AlfrescoSolrDataModel.getInstance().isDerivedDateField(fieldNameAndEnding.getSecond()))
|
||||
{
|
||||
if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE)
|
||||
|| propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME )))
|
||||
{
|
||||
return subQueryBuilder.getQuery(
|
||||
AlfrescoSolrDataModel.getInstance()
|
||||
.getDateDerivedFIeld(propertyQName) + fieldNameAndEnding.getSecond(),
|
||||
queryText, analysisMode, luceneFunction);
|
||||
}
|
||||
}
|
||||
|
||||
// Already in expanded form
|
||||
|
||||
|
||||
Reference in New Issue
Block a user