mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
75005: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 70182: WIP, allows date ranges for solr stats queries git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@75334 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -10,6 +10,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The results of executing a solr stats query
|
||||
@@ -31,10 +32,13 @@ public class SolrStatsResult implements JSONResult, StatsResultSet
|
||||
private Long mean;
|
||||
|
||||
private List<StatsResultStat> stats;
|
||||
public SolrStatsResult(JSONObject json)
|
||||
private boolean nameIsADate;
|
||||
|
||||
public SolrStatsResult(JSONObject json, boolean nameIsADate)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.nameIsADate = nameIsADate;
|
||||
stats = new ArrayList<>();
|
||||
processJson(json);
|
||||
}
|
||||
@@ -109,7 +113,7 @@ public class SolrStatsResult implements JSONResult, StatsResultSet
|
||||
*/
|
||||
private StatsResultStat processStat(String name, JSONObject facetVal) throws JSONException
|
||||
{
|
||||
return new StatsResultStat(name,
|
||||
return new StatsResultStat(nameIsADate?formatAsDate(name):name,
|
||||
facetVal.getLong("sum"),
|
||||
facetVal.getLong("count"),
|
||||
facetVal.getLong("min"),
|
||||
@@ -117,6 +121,29 @@ public class SolrStatsResult implements JSONResult, StatsResultSet
|
||||
facetVal.getLong("mean"));
|
||||
}
|
||||
|
||||
public static String formatAsDate(String name)
|
||||
{
|
||||
if (StringUtils.hasText(name))
|
||||
{
|
||||
try
|
||||
{
|
||||
//LocalDate d = LocalDate.parse(name);
|
||||
//return d.toString();
|
||||
return name.substring(0,10);
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Can't parse reponse: "+iae.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Default
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@@ -214,7 +214,7 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
|
||||
* @param searchParameters
|
||||
* @return SolrStatsResult
|
||||
*/
|
||||
public SolrStatsResult executeStatsQuery(StatsParameters searchParameters)
|
||||
public SolrStatsResult executeStatsQuery(final StatsParameters searchParameters)
|
||||
{
|
||||
if(repositoryState.isBootstrapping())
|
||||
{
|
||||
@@ -235,7 +235,7 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
|
||||
@Override
|
||||
public SolrStatsResult getResult(JSONObject json)
|
||||
{
|
||||
return new SolrStatsResult(json);
|
||||
return new SolrStatsResult(json, searchParameters.isDateSearch());
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -66,7 +66,7 @@ public class SolrQueryHTTPClientTest
|
||||
luceneQuery.append(" +TYPE:\"" + ContentModel.TYPE_CONTENT + "\"");
|
||||
|
||||
String filterQuery = "ANCESTOR:\"workspace://SpacesStore/a1c1a0a1-9d68-4912-b853-b3b277f31288\"";
|
||||
StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, luceneQuery.toString(), filterQuery);
|
||||
StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, luceneQuery.toString(), filterQuery, false);
|
||||
params.addSort(new SortDefinition(SortDefinition.SortType.FIELD, "contentsize", false));
|
||||
params.addStatsParameter(StatsParameters.PARAM_FIELD, "contentsize");
|
||||
params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX+ContentModel.PROP_CREATED.toString());
|
||||
|
@@ -7,6 +7,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class SolrStatsResultTest
|
||||
{
|
||||
@@ -26,10 +27,22 @@ public class SolrStatsResultTest
|
||||
SolrStatsResult resultMod = testProcessing(TEST_MODIFIER, 9, 4, 188);
|
||||
SolrStatsResult resultV = testProcessing(TEST_VERSIONLABEL_DOT, 6, 0, 190);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSolrStatsResultDateFormat() throws JSONException
|
||||
{
|
||||
String date = SolrStatsResult.formatAsDate(null);
|
||||
assertNotNull(date);
|
||||
assertTrue(!StringUtils.hasText(date));
|
||||
|
||||
assertEquals("2011-03-03", SolrStatsResult.formatAsDate("2011-03-03T10:34:53.551Z"));
|
||||
assertEquals("2014-05-12", SolrStatsResult.formatAsDate("2014-05-12T16:26:53.292Z"));
|
||||
}
|
||||
|
||||
private SolrStatsResult testProcessing(String testData, long queryTime, int statsSize, long numberFound) throws JSONException
|
||||
{
|
||||
JSONObject json = new JSONObject(new JSONTokener(testData));
|
||||
SolrStatsResult result = new SolrStatsResult(json);
|
||||
SolrStatsResult result = new SolrStatsResult(json, false);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(numberFound, result.getNumberFound());
|
||||
@@ -39,7 +52,6 @@ public class SolrStatsResultTest
|
||||
assertTrue(result.getMax()==3737049);
|
||||
assertTrue(result.getMean()==82362);
|
||||
assertEquals(statsSize, result.getStats().size());
|
||||
System.out.println(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user