CMIS: Normalisation of scores in 0..1 range (due to standard statements) (#377)

This commit is contained in:
Angel Borroy
2019-03-26 10:31:34 +01:00
committed by GitHub
parent 2bd95949e9
commit f643b62834
3 changed files with 63 additions and 31 deletions

View File

@@ -37,8 +37,14 @@ import org.apache.chemistry.opencmis.commons.enums.PropertyType;
public class CMISResultSetColumn implements ResultSetColumn public class CMISResultSetColumn implements ResultSetColumn
{ {
// Constant used at alfresco-data-model > org.alfresco.opencmis.search.CMISQueryParser.buildColumns()
public static final String SCORE_SELECTOR_ID = "SEARCH_SCORE";
public static final String SCORE_SELECTOR_FUNCTION = "Score";
private String name; private String name;
private String functionName;
private PropertyDefinitionWrapper propertyDefinition; private PropertyDefinitionWrapper propertyDefinition;
private PropertyType dataType; private PropertyType dataType;
@@ -47,10 +53,11 @@ public class CMISResultSetColumn implements ResultSetColumn
private QName alfrescoDataTypeQName; private QName alfrescoDataTypeQName;
CMISResultSetColumn(String name, PropertyDefinitionWrapper propertyDefinition, PropertyType dataType, CMISResultSetColumn(String name, String functionName, PropertyDefinitionWrapper propertyDefinition, PropertyType dataType,
QName alfrescoPropertyQName, QName alfrescoDataTypeQName) QName alfrescoPropertyQName, QName alfrescoDataTypeQName)
{ {
this.name = name; this.name = name;
this.functionName = functionName;
this.propertyDefinition = propertyDefinition; this.propertyDefinition = propertyDefinition;
this.dataType = dataType; this.dataType = dataType;
this.alfrescoPropertyQName = alfrescoPropertyQName; this.alfrescoPropertyQName = alfrescoPropertyQName;
@@ -62,6 +69,11 @@ public class CMISResultSetColumn implements ResultSetColumn
return name; return name;
} }
public String getFunctionName()
{
return functionName;
}
public PropertyDefinitionWrapper getCMISPropertyDefinition() public PropertyDefinitionWrapper getCMISPropertyDefinition()
{ {
return propertyDefinition; return propertyDefinition;
@@ -81,4 +93,5 @@ public class CMISResultSetColumn implements ResultSetColumn
{ {
return alfrescoPropertyQName; return alfrescoPropertyQName;
} }
} }

View File

@@ -106,7 +106,8 @@ public class CMISResultSetMetaData implements ResultSetMetaData
{ {
alfrescoDataTypeQName = cmisDictionaryService.findAlfrescoDataType(type); alfrescoDataTypeQName = cmisDictionaryService.findAlfrescoDataType(type);
} }
CMISResultSetColumn cmd = new CMISResultSetColumn(column.getAlias(), propertyDefinition, type, CMISResultSetColumn cmd = new CMISResultSetColumn(column.getAlias(), column.getFunction().getName(),
propertyDefinition, type,
alfrescoPropertyQName, alfrescoDataTypeQName); alfrescoPropertyQName, alfrescoDataTypeQName);
columnMetaData.put(cmd.getName(), cmd); columnMetaData.put(cmd.getName(), cmd);
} }

View File

@@ -176,7 +176,14 @@ public class CMISResultSetRow implements ResultSetRow
context.setScore(getScore()); context.setScore(getScore());
for (Column column : query.getColumns()) for (Column column : query.getColumns())
{ {
if (column.getAlias().equals(columnName))
// When an SCORE selector is included, score must be adapted to range 0..1 due to CMIS specification
if (column.getAlias().equals(CMISResultSetColumn.SCORE_SELECTOR_ID) ||
column.getFunction().getName().equals(CMISResultSetColumn.SCORE_SELECTOR_FUNCTION))
{
return getNormalisedScore();
}
else if (column.getAlias().equals(columnName))
{ {
return column.getFunction().getValue(column.getFunctionArguments(), context); return column.getFunction().getValue(column.getFunctionArguments(), context);
} }
@@ -222,6 +229,17 @@ public class CMISResultSetRow implements ResultSetRow
return null; return null;
} }
/**
/**
* CMIS Specification states that scoring results must be in a 0..1 range
* This function re-adapt the scores when any scoring field or expression is requested by the query.
* It's a safe approach, as includes negative numbers and also paged requests.
* @return
*/
private float getNormalisedScore() {
return (float) (Math.atan(getScore()) / Math.PI) + 0.5f;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *