mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged searchrep (5.2.1) to 5.2.N (5.2.1)
136624 gjames: SEARCH-409: Better handling of stats metric response git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137033 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
@@ -39,8 +40,10 @@ import org.alfresco.repo.search.SimpleResultSetMetaData;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -415,12 +418,21 @@ public class SolrJSONResultSet implements ResultSet, JSONResult
|
||||
{
|
||||
return metrics.entrySet().stream().map(aStat -> {
|
||||
METRIC_TYPE metricType = METRIC_TYPE.valueOf(aStat.getKey());
|
||||
Object val = aStat.getValue();
|
||||
if (JSONObject.NULL.equals(val)) return null;
|
||||
|
||||
switch (metricType)
|
||||
{
|
||||
case distinctValues:
|
||||
return new ListMetric(metricType, val);
|
||||
case percentiles:
|
||||
return new PercentileMetric(metricType, val);
|
||||
case mean:
|
||||
if ("NaN".equals(String.valueOf(val))) return null; //else fall through
|
||||
default:
|
||||
return new SimpleMetric(metricType, String.valueOf(aStat.getValue()));
|
||||
return new SimpleMetric(metricType, val);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*-
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.search.impl.solr.facet.facetsresponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A metric with one value
|
||||
*/
|
||||
public class ListMetric implements Metric
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(ListMetric.class);
|
||||
private final METRIC_TYPE type;
|
||||
private final Map<String, Object> value = new HashMap<>(1);
|
||||
|
||||
public ListMetric(METRIC_TYPE type, Object val)
|
||||
{
|
||||
this.type = type;
|
||||
try
|
||||
{
|
||||
JSONArray jsonArray = (JSONArray) val;
|
||||
List<Object> values = new ArrayList<>(jsonArray.length());
|
||||
for(int i = 0; i < jsonArray.length(); i++)
|
||||
{
|
||||
values.add(jsonArray.get(i));
|
||||
}
|
||||
value.put(type.toString(), values);
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
logger.debug("ClassCastException for "+val);
|
||||
}
|
||||
catch (JSONException e)
|
||||
{
|
||||
logger.debug("Failed to process "+val+ " "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public METRIC_TYPE getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ import java.util.Map;
|
||||
*/
|
||||
public interface Metric
|
||||
{
|
||||
public static enum METRIC_TYPE {count, min, max, sum, missing, sumOfSquares, mean, stddev};
|
||||
public static enum METRIC_TYPE {count, min, max, sum, missing, sumOfSquares, mean, stddev, countDistinct, cardinality, distinctValues, percentiles};
|
||||
|
||||
METRIC_TYPE getType();
|
||||
Map<String, Object> getValue();
|
||||
|
@@ -0,0 +1,82 @@
|
||||
/*-
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.search.impl.solr.facet.facetsresponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A metric with one value
|
||||
*/
|
||||
public class PercentileMetric implements Metric
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(PercentileMetric.class);
|
||||
private final METRIC_TYPE type;
|
||||
private final Map<String, Object> value = new HashMap<>(1);
|
||||
|
||||
public PercentileMetric(METRIC_TYPE type, Object val)
|
||||
{
|
||||
this.type = type;
|
||||
try
|
||||
{
|
||||
JSONArray jsonArray = (JSONArray) val;
|
||||
Map<String,Number> percentiles = new HashMap<>(jsonArray.length()/2);
|
||||
|
||||
for (int i = 0, length = jsonArray.length(); i < length; i++)
|
||||
{
|
||||
percentiles.put(jsonArray.getString(i++),jsonArray.getDouble(i));
|
||||
}
|
||||
value.put(type.toString(), percentiles);
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
logger.debug("ClassCastException for "+val);
|
||||
}
|
||||
catch (JSONException e)
|
||||
{
|
||||
logger.debug("Failed to process percentile for "+val+ " "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public METRIC_TYPE getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
@@ -1,3 +1,28 @@
|
||||
/*-
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.search.impl.solr.facet.facetsresponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -11,7 +36,7 @@ public class SimpleMetric implements Metric
|
||||
private final METRIC_TYPE type;
|
||||
private final Map<String, Object> value = new HashMap<>(1);
|
||||
|
||||
public SimpleMetric(METRIC_TYPE type, String val)
|
||||
public SimpleMetric(METRIC_TYPE type, Object val)
|
||||
{
|
||||
this.type = type;
|
||||
value.put(type.toString(), val);
|
||||
|
Reference in New Issue
Block a user