dataset.setRowLabelAttr(0, getAttributes(dataSetQuery.getName(), dataSetQuery, context));
}else{
// We need to get the max objects and the next part of the query on them (next part beeing the datasettimequery
ObjectCount[] maxObjectCounts = SolrLogger.queryFacetField(query, filterQuery, dataSetQuery.getFacetField(), dataSetQuery.getMax(), false, null);
for (int j = 0; j < maxObjectCounts.length; j++) {
ObjectCount firstCount = maxObjectCounts[j];
String newQuery = dataSetQuery.getFacetField() + ": " + ClientUtils.escapeQueryChars(firstCount.getValue()) + " AND " + query;
ObjectCount[] maxDateFacetCounts = SolrLogger.queryFacetDate(newQuery, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(), dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context);
// Make sure we have a dataSet
if(dataset == null)
{
dataset = new Dataset(maxObjectCounts.length, maxDateFacetCounts.length);
}
// TODO: this is a very dirty fix change this ! ! ! ! ! !
dataset.setRowLabel(j, getResultName(firstCount.getValue(), dataSetQuery, context));
dataset.setRowLabelAttr(j, getAttributes(firstCount.getValue(), dataSetQuery, context));
for (int k = 0; k < maxDateFacetCounts.length; k++) {
ObjectCount objectCount = maxDateFacetCounts[k];
// No need to add this many times
if(j == 0)
{
dataset.setColLabel(k, objectCount.getValue());
}
dataset.addValueToMatrix(j, k, objectCount.getCount());
}
}
if(dataset != null && !(getDatasetGenerators().get(0) instanceof DatasetTimeGenerator)){
dataset.flipRowCols();
}
}
}
}
}else{
// We do NOT have a date facet so just do queries after each other
/*
for (int i = 0; i < datasetQueries.size(); i++) {
DatasetQuery datasetQuery = datasetQueries.get(i);
if(datasetQuery.getQueries().size() != 1){
// TODO: do this
}else{
String query = datasetQuery.getQueries().get(0);
// Loop over the queries & do em
// ObjectCount[] topCounts = SolrLogger.queryFacetField(query, );
}
}
*/
DatasetQuery firsDataset = datasetQueries.get(0);
//Do the first query
ObjectCount[] topCounts1 = null;
// if(firsDataset.getQueries().size() == 1){
topCounts1 = queryFacetField(firsDataset, firsDataset.getQueries().get(0).getQuery(), filterQuery);
// }else{
// TODO: do this
// }
// Check if we have more queries that need to be done
if(datasetQueries.size() == 2){
DatasetQuery secondDataSet = datasetQueries.get(1);
// Now do the second one
ObjectCount[] topCounts2 = queryFacetField(secondDataSet, secondDataSet.getQueries().get(0).getQuery(), filterQuery);
// Now that have results for both of them lets do x.y queries
List<String> facetQueries = new ArrayList<String>();
for (ObjectCount count2 : topCounts2) {
String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
// Check if we also have a type present (if so this should be put into the query)
if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
{
facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();
}
facetQueries.add(facetQuery);
}
for (int i = 0; i < topCounts1.length; i++){
ObjectCount count1 = topCounts1[i];
ObjectCount[] currentResult = new ObjectCount[topCounts2.length];
// Make sure we have a dataSet
if(dataset == null)
{
dataset = new Dataset(topCounts2.length, topCounts1.length);
}
dataset.setColLabel(i, getResultName(count1.getValue(), firsDataset, context));
dataset.setColLabelAttr(i, getAttributes(count1.getValue(), firsDataset, context));
String query = firsDataset.getFacetField() + ":" + ClientUtils.escapeQueryChars(count1.getValue());
// Check if we also have a type present (if so this should be put into the query)
if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
{
query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();
}
Map<String, Integer> facetResult = SolrLogger.queryFacetQuery(query, filterQuery, facetQueries);
// TODO: the show total
// No need to add this many times
// TODO: dit vervangen door te displayen value
for (int j = 0; j < topCounts2.length; j++) {
ObjectCount count2 = topCounts2[j];
if(i == 0) {
dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));
}
// Get our value the value is the same as the query
String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
// Check if we also have a type present (if so this should be put into the query
if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
{
facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();
}
// We got our query so now get the value
dataset.addValueToMatrix(j, i, facetResult.get(facetQuery));
}
/*
for (int j = 0; j < topCounts2.length; j++) {
ObjectCount count2 = topCounts2[j];
String query = firsDataset.getFacetField() + ":" + count1.getValue();
// Check if we also have a type present (if so this should be put into the query
if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();
query += " AND " + secondDataSet.getFacetField() + ":" + count2.getValue();
// Check if we also have a type present (if so this should be put into the query
if("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
query += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();
long count = SolrLogger.queryFacetQuery(query, filterQuery);
// TODO: the show total
// No need to add this many times
// TODO: dit vervangen door te displayen value
if(i == 0) {
dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));
}
dataset.addValueToMatrix(j, i, count);
}
*/
}
// System.out.println("BOTH");
} else{
// Make sure we have a dataSet
dataset = new Dataset(1, topCounts1.length);
for (int i = 0; i < topCounts1.length; i++) {
ObjectCount count = topCounts1[i];
dataset.setColLabel(i, getResultName(count.getValue(), firsDataset, context));
dataset.setColLabelAttr(i, getAttributes(count.getValue(), firsDataset, context));
dataset.addValueToMatrix(0, i, count.getCount());
}
}
}
if(dataset != null){