If SPARQL won't do it for me, I'll just have to do it myself...
Well, it's easy in php:
foreach ($prepared_aggregates as $key => $row) {
$count[$key] = $row["count"];
}
array_multisort($count, SORT_NUMERIC,SORT_DESC, $prepared_aggregates);
1
I started to write one in Java, but it was slower under Quercus because of type conversions
private Hashtable[] doOrderBy(
Hashtable[] results,
String[] order_by,
String[] sorting
){
/**
* a container for the return values
* */
//Hashtable<String,String>
int resultlength = results.length;
Hashtable[] final_result = new Hashtable[resultlength] ; //new Hashtable<Integer, Hashtable<String,String>>();
/**
* a mapping for looking up keys of the provided results when the sorting is complete
* */
Hashtable<String,Integer> mapTable = new Hashtable<String,Integer>();
/**
* the array of strings for sorting
* */
ArrayList<String> sortingTable = new ArrayList<String>();
/**
* a container for the sort string
* */
String sortstring;
//Enumeration<Integer> resultKeys = results.keys();
//Enumeration<String> orders;
String order_key;
String order_value;
Iterator it;
Hashtable<String,String> row = new Hashtable<String,String>();
int rownumber=0;
int or_num = order_by.length;
//iterate over the results
for(int j=0;j<resultlength;j++){
sortstring = "";
//rownumber = resultKeys.nextElement();
row = results[j];
//orders = order_by.keys();
//iterate over the orders
for(int i=0;i< or_num ; i++) {
order_key = order_by[i];
//order_key = orders.nextElement();
//order_value = order_by.get(order_key);
sortstring += row.get(order_key);
}
//get the string from the row and addit to the sortstring
mapTable.put(sortstring,j);
sortingTable.add(sortstring);
}
//sort the sortTable
Collections.sort(sortingTable); //add MIXED ASC DESC
it = sortingTable.iterator();
//iterate the sort table
//retrieve the result key from the sortable
//get the hashtable result row from the results
//place in the final results with the new sorted index
rownumber = 0;
String[] debugger = new String[results.length];
while (it.hasNext()) {
order_key = (String)it.next();
final_result[rownumber] = results[mapTable.get(order_key)];
// debugger[rownumber] = order_key;
rownumber++;
}
//return debugger;
return final_result;
}
1
http://java.sun.com/docs/books/tutorial/collections/algorithms/index.html
http://java.sun.com/javase/6/docs/api/java/util/Collections.html
http://java.sun.com/javase/6/docs/api/java/util/Comparator.html