From 590f39b4037ca0146e944bc35d4d18e1a07aac3a Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 9 Jan 2022 16:06:14 +0100 Subject: [PATCH] Add Sorting functionality to Crawler Queue Table Allow to sort for count and host --- htroot/IndexCreateQueues_p.html | 14 +++++-- htroot/IndexCreateQueues_p.java | 67 ++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/htroot/IndexCreateQueues_p.html b/htroot/IndexCreateQueues_p.html index 2de295770..ec865db06 100644 --- a/htroot/IndexCreateQueues_p.html +++ b/htroot/IndexCreateQueues_p.html @@ -50,10 +50,17 @@ + #(showtable)# - Count + + Count + #(sortedByCount)#::#(/sortedByCount)# + Delta/ms - Host + + Host + #(sortedByHost)#::#(/sortedByHost)# + Initiator Profile Depth @@ -61,6 +68,7 @@ Anchor Name URL + #(/showtable)# #{host}# #[hostcount]# @@ -94,4 +102,4 @@ --> - \ No newline at end of file + diff --git a/htroot/IndexCreateQueues_p.java b/htroot/IndexCreateQueues_p.java index 27f0b4aae..766a9e635 100644 --- a/htroot/IndexCreateQueues_p.java +++ b/htroot/IndexCreateQueues_p.java @@ -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 hosts = sb.crawlQueues.noticeURL.getDomainStackHosts(stackType, sb.robots); + Map 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 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 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 hosts_sorted = new TreeMap(Collections.reverseOrder()); + hosts_sorted.putAll(hosts); + hosts = hosts_sorted; + } + else { + prop.put("crawler_showtable_sortedByHost_asc", true); + Map hosts_sorted = new TreeMap(hosts); + hosts = hosts_sorted; + } + } + } int hc = 0; for (Map.Entry host: hosts.entrySet()) {