Add Sorting functionality to Crawler Queue Table

Allow to sort for count and host
pull/439/head
Andreas 2 years ago committed by GitHub
parent 41e87a44bc
commit 590f39b403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,10 +50,17 @@
<col width="10" />
<col />
</colgroup>
#(showtable)#
<tr class="TableHeader">
<th>Count</th>
<th #(sortedByCount)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByCount)#>
<a class="sortTableLink" href="IndexCreateQueues_p.html?stack=#[queuename]#&amp;sort=#(sortedByCount_asc)#::-#(/sortedByCount_asc)#count" target="_self" title="Sort #(sortedByCount_asc)#ascending::descending#(/sortedByCount_asc)#">Count</a>
#(sortedByCount)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByCount)#
</th>
<th>Delta/ms</th>
<th>Host</th>
<th #(sortedByHost)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByHost)#>
<a class="sortTableLink" href="IndexCreateQueues_p.html?stack=#[queuename]#&amp;sort=#(sortedByHost_asc)#::-#(/sortedByHost_asc)#host" target="_self" title="Sort #(sortedByHost_asc)#ascending::descending#(/sortedByHost_asc)#">Host</a>
#(sortedByHost)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByHost)#
</th>
<th>Initiator</th>
<th>Profile</th>
<th>Depth</th>
@ -61,6 +68,7 @@
<th>Anchor Name</th>
<th>URL</th>
</tr>
#(/showtable)#
#{host}#
<tr class="TableCellDark">
<td>#[hostcount]#</td>
@ -94,4 +102,4 @@
-->
</script>
</body>
</html>
</html>

@ -9,6 +9,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.LinkedHashMap;
import java.util.TreeMap;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@ -59,7 +64,9 @@ public class IndexCreateQueues_p {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
StackType stackType = StackType.LOCAL;
int urlsPerHost = 5;
int urlsPerHost = 3;
int sortByCount = 0;
int sortByHost = 0;
boolean embed = false;
String deletepattern = ".*";
@ -68,6 +75,14 @@ public class IndexCreateQueues_p {
urlsPerHost = post.getInt("urlsPerHost", urlsPerHost);
if (post.containsKey("embed")) embed = true;
if (post.containsKey("sort")) {
String countSort = post.get("sort");
if (countSort.equals("count")) sortByCount = +1;
if (countSort.equals("-count")) sortByCount = -1;
if (countSort.equals("host")) sortByHost = +1;
if (countSort.equals("-host")) sortByHost = -1;
}
if (post.containsKey("delete")) {
deletepattern = post.get("pattern", deletepattern).trim();
final int option = post.getInt("option", INVALID);
@ -149,7 +164,55 @@ public class IndexCreateQueues_p {
prop.put("crawler_embed_deletepattern", deletepattern);
prop.put("crawler_embed_queuename", stackType.name());
final Map<String, Integer[]> hosts = sb.crawlQueues.noticeURL.getDomainStackHosts(stackType, sb.robots);
Map<String, Integer[]> hosts = sb.crawlQueues.noticeURL.getDomainStackHosts(stackType, sb.robots);
prop.put("crawler_showtable_queuename", stackType.name());
if ( sortByCount==0 && sortByHost==0 ) {
prop.put("crawler_showtable_sortedByCount",false);
prop.put("crawler_showtable_sortedByCount_asc",true); // first click sorts descending
prop.put("crawler_showtable_sortedByHost",false);
prop.put("crawler_showtable_sortedByHost_asc",false);
}
else {
if ( sortByCount!=0 ) {
prop.put("crawler_showtable_sortedByHost",false);
prop.put("crawler_showtable_sortedByHost_asc",false);
prop.put("crawler_showtable_sortedByCount",true);
if (sortByCount < 0) {
prop.put("crawler_showtable_sortedByCount_asc", false);
Map<String, Integer[]> hosts_sorted = hosts.entrySet().stream()
.sorted( (e1, e2)->e2.getValue()[0].compareTo(e1.getValue()[0]) )
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
hosts = hosts_sorted;
}
else {
prop.put("crawler_showtable_sortedByCount_asc", true);
Map<String, Integer[]> hosts_sorted = hosts.entrySet().stream()
.sorted( (e1, e2)->e1.getValue()[0].compareTo(e2.getValue()[0]) )
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
hosts = hosts_sorted;
}
}
if ( sortByHost!=0 ) {
prop.put("crawler_showtable_sortedByCount",false);
prop.put("crawler_showtable_sortedByCount_asc",true);
prop.put("crawler_showtable_sortedByHost",true);
if (sortByHost < 0) {
prop.put("crawler_showtable_sortedByHost_asc", false);
Map<String, Integer[]> hosts_sorted = new TreeMap<String, Integer[]>(Collections.reverseOrder());
hosts_sorted.putAll(hosts);
hosts = hosts_sorted;
}
else {
prop.put("crawler_showtable_sortedByHost_asc", true);
Map<String, Integer[]> hosts_sorted = new TreeMap<String, Integer[]>(hosts);
hosts = hosts_sorted;
}
}
}
int hc = 0;
for (Map.Entry<String, Integer[]> host: hosts.entrySet()) {

Loading…
Cancel
Save