mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
CMIS: Normalisation of scores in 0..1 range (due to standard statements) (#377)
This commit is contained in:
@@ -37,8 +37,14 @@ import org.apache.chemistry.opencmis.commons.enums.PropertyType;
|
||||
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 functionName;
|
||||
|
||||
private PropertyDefinitionWrapper propertyDefinition;
|
||||
|
||||
private PropertyType dataType;
|
||||
@@ -47,10 +53,11 @@ public class CMISResultSetColumn implements ResultSetColumn
|
||||
|
||||
private QName alfrescoDataTypeQName;
|
||||
|
||||
CMISResultSetColumn(String name, PropertyDefinitionWrapper propertyDefinition, PropertyType dataType,
|
||||
CMISResultSetColumn(String name, String functionName, PropertyDefinitionWrapper propertyDefinition, PropertyType dataType,
|
||||
QName alfrescoPropertyQName, QName alfrescoDataTypeQName)
|
||||
{
|
||||
this.name = name;
|
||||
this.functionName = functionName;
|
||||
this.propertyDefinition = propertyDefinition;
|
||||
this.dataType = dataType;
|
||||
this.alfrescoPropertyQName = alfrescoPropertyQName;
|
||||
@@ -62,6 +69,11 @@ public class CMISResultSetColumn implements ResultSetColumn
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFunctionName()
|
||||
{
|
||||
return functionName;
|
||||
}
|
||||
|
||||
public PropertyDefinitionWrapper getCMISPropertyDefinition()
|
||||
{
|
||||
return propertyDefinition;
|
||||
@@ -81,4 +93,5 @@ public class CMISResultSetColumn implements ResultSetColumn
|
||||
{
|
||||
return alfrescoPropertyQName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -106,7 +106,8 @@ public class CMISResultSetMetaData implements ResultSetMetaData
|
||||
{
|
||||
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);
|
||||
columnMetaData.put(cmd.getName(), cmd);
|
||||
}
|
||||
|
@@ -176,7 +176,14 @@ public class CMISResultSetRow implements ResultSetRow
|
||||
context.setScore(getScore());
|
||||
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);
|
||||
}
|
||||
@@ -222,6 +229,17 @@ public class CMISResultSetRow implements ResultSetRow
|
||||
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)
|
||||
*
|
||||
|
Reference in New Issue
Block a user