From f3f99b19c696a8ba380b381a34342a9f012b0a8e Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 19 Jan 2007 01:45:29 +0000 Subject: [PATCH] extended search statistics git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3249 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/SearchStatistics_p.html | 45 ++++++++- htroot/SearchStatistics_p.java | 94 +++++++++++++------ htroot/yacy/search.java | 3 + source/de/anomic/net/natLib.java | 18 ++++ .../de/anomic/plasma/plasmaSwitchboard.java | 2 + source/de/anomic/yacy/yacySeed.java | 17 +--- 6 files changed, 130 insertions(+), 49 deletions(-) diff --git a/htroot/SearchStatistics_p.html b/htroot/SearchStatistics_p.html index 600f18a17..c771ff8f8 100644 --- a/htroot/SearchStatistics_p.html +++ b/htroot/SearchStatistics_p.html @@ -9,8 +9,10 @@ #(page)# @@ -27,6 +29,7 @@ Requesting Host Date + Offset Expected Results Returned Results Expected Time @@ -37,6 +40,7 @@ #[host]# #[date]# + #[offset]# #[querycount]# #[resultcount]# #[querytime]# @@ -46,6 +50,23 @@ #{/list}# :: +

Search Statistics: Local Searche Tracker

+

This is a list of searches that had been requested from this' peer search interface

+

Showing #[num]# entries from a total of #[total]# Requests.

+ + + + + + + #{list}# + + + + + + #{/list}# +
Requesting HostCountAccess Dates
#[host]##[count]##[dates]#
::

Search Statistics: Remote Searches

This is a list of searches that had been requested from remote peer search interface

@@ -53,6 +74,7 @@ + @@ -63,6 +85,7 @@ #{list}# + @@ -72,6 +95,24 @@ #{/list}#
Requesting HostPeer Name Date Expected Results Returned Results
#[host]##[peername]# #[date]# #[querycount]# #[resultcount]#
+ :: +

Search Statistics: Remote Searche Tracker

+

This is a list of searches that had been requested from remote peer search interface

+

Showing #[num]# entries from a total of #[total]# Requests.

+ + + + + + + #{list}# + + + + + + #{/list}# +
Requesting HostCountAccess Dates
#[host]##[count]##[dates]#
#(/page)# #%env/templates/footer.template%# diff --git a/htroot/SearchStatistics_p.java b/htroot/SearchStatistics_p.java index 9b990cdee..491e9ca15 100644 --- a/htroot/SearchStatistics_p.java +++ b/htroot/SearchStatistics_p.java @@ -29,12 +29,14 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaSearchQuery; import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; +import de.anomic.yacy.yacyCore; public class SearchStatistics_p { @@ -50,42 +52,72 @@ public class SearchStatistics_p { int maxCount = 100; int entCount = 0; boolean dark = true; - Iterator i = (page <= 2) ? switchboard.localSearches.entrySet().iterator() : switchboard.remoteSearches.entrySet().iterator() ; Map.Entry entry; - Long trackerHandle; - HashMap searchProfile; - StringBuffer a = null; - while ((entCount < maxCount) && (i.hasNext())) { - entry = (Map.Entry) i.next(); - trackerHandle = (Long) entry.getKey(); - searchProfile = (HashMap) entry.getValue(); + if ((page == 1) || (page == 3)) { + Iterator i = (page == 1) ? switchboard.localSearches.entrySet().iterator() : switchboard.remoteSearches.entrySet().iterator(); + Long trackerHandle; + HashMap searchProfile; + StringBuffer a = null; + while ((entCount < maxCount) && (i.hasNext())) { + entry = (Map.Entry) i.next(); + trackerHandle = (Long) entry.getKey(); + searchProfile = (HashMap) entry.getValue(); - if (page <= 2) { - Iterator wi = ((Set) searchProfile.get("querywords")).iterator(); - a = new StringBuffer(); - while (wi.hasNext()) a.append((String) wi.next()).append(' '); - } + if (page == 1) { + Iterator wi = ((Set) searchProfile.get("querywords")).iterator(); + a = new StringBuffer(); + while (wi.hasNext()) a.append((String) wi.next()).append(' '); + } - // put values in template - prop.put("page_list_" + entCount + "_dark", ((dark) ? 1 : 0) ); dark =! dark; - prop.put("page_list_" + entCount + "_host", (String) searchProfile.get("host")); - prop.put("page_list_" + entCount + "_date", (new Date(trackerHandle.longValue())).toString()); - if (page <= 2) { - prop.put("page_list_" + entCount + "_querywords", new String(a)); - } else { - prop.put("page_list_" + entCount + "_queryhashes", plasmaSearchQuery.anonymizedQueryHashes((Set) searchProfile.get("queryhashes"))); - } - prop.put("page_list_" + entCount + "_querycount", ((Integer) searchProfile.get("querycount")).toString()); - prop.put("page_list_" + entCount + "_querytime", ((Long) searchProfile.get("querytime")).toString()); - prop.put("page_list_" + entCount + "_resultcount", ((Integer) searchProfile.get("resultcount")).toString()); - prop.put("page_list_" + entCount + "_resulttime", ((Long) searchProfile.get("resulttime")).toString()); + // put values in template + prop.put("page_list_" + entCount + "_dark", ((dark) ? 1 : 0) ); dark =! dark; + prop.put("page_list_" + entCount + "_host", (String) searchProfile.get("host")); + prop.put("page_list_" + entCount + "_date", yacyCore.universalDateShortString(new Date(trackerHandle.longValue()))); + if (page == 1) { + // local search + prop.put("page_list_" + entCount + "_offset", ((Integer) searchProfile.get("offset")).toString()); + prop.put("page_list_" + entCount + "_querywords", new String(a)); + } else { + // remote search + prop.put("page_list_" + entCount + "_peername", (String) searchProfile.get("peername")); + prop.put("page_list_" + entCount + "_queryhashes", plasmaSearchQuery.anonymizedQueryHashes((Set) searchProfile.get("queryhashes"))); + } + prop.put("page_list_" + entCount + "_querycount", ((Integer) searchProfile.get("querycount")).toString()); + prop.put("page_list_" + entCount + "_querytime", ((Long) searchProfile.get("querytime")).toString()); + prop.put("page_list_" + entCount + "_resultcount", ((Integer) searchProfile.get("resultcount")).toString()); + prop.put("page_list_" + entCount + "_resulttime", ((Long) searchProfile.get("resulttime")).toString()); - // next - entCount++; + // next + entCount++; + } + prop.put("page_list", entCount); + prop.put("page_num", entCount); + prop.put("page_total", (page == 1) ? switchboard.localSearches.size() : switchboard.remoteSearches.size()); + } + if ((page == 2) || (page == 4)) { + Iterator i = (page == 2) ? switchboard.localSearchTracker.entrySet().iterator() : switchboard.remoteSearchTracker.entrySet().iterator(); + String host, handlestring; + TreeSet handles; + while ((entCount < maxCount) && (i.hasNext())) { + entry = (Map.Entry) i.next(); + host = (String) entry.getKey(); + handles = (TreeSet) entry.getValue(); + handlestring = ""; + Iterator ii = handles.iterator(); + while (ii.hasNext()) { + handlestring += yacyCore.universalDateShortString(new Date(((Long) ii.next()).longValue())) + " "; + } + prop.put("page_list_" + entCount + "_dark", ((dark) ? 1 : 0) ); dark =! dark; + prop.put("page_list_" + entCount + "_host", host); + prop.put("page_list_" + entCount + "_count", new Integer(handles.size()).toString()); + prop.put("page_list_" + entCount + "_dates", handlestring); + // next + entCount++; + } + prop.put("page_list", entCount); + prop.put("page_num", entCount); + prop.put("page_total", (page == 2) ? switchboard.localSearches.size() : switchboard.remoteSearches.size()); } - prop.put("page_list", entCount); - prop.put("page_num", entCount); - prop.put("page_total", (page <= 2) ? switchboard.localSearches.size() : switchboard.remoteSearches.size()); // return rewrite properties return prop; } diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index af2a7db7f..10aea030d 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -56,6 +56,7 @@ import java.util.TreeSet; import de.anomic.http.httpHeader; import de.anomic.kelondro.kelondroBitfield; import de.anomic.index.indexContainer; +import de.anomic.net.natLib; import de.anomic.plasma.plasmaURL; import de.anomic.index.indexURLEntry; import de.anomic.plasma.plasmaCondenser; @@ -247,6 +248,8 @@ public final class search { searchProfile.put("resultcount", new Integer(joincount)); String client = (String) header.get("CLIENTIP"); searchProfile.put("host", client); + yacySeed remotepeer = yacyCore.seedDB.lookupByIP(natLib.getInetAddress(client), true, false, false); + searchProfile.put("peername", (remotepeer == null) ? "unknown" : remotepeer.getName()); sb.remoteSearches.put(trackerHandle, searchProfile); TreeSet handles = (TreeSet) sb.remoteSearchTracker.get(client); if (handles == null) handles = new TreeSet(); diff --git a/source/de/anomic/net/natLib.java b/source/de/anomic/net/natLib.java index 9147edfe9..ed00ec366 100644 --- a/source/de/anomic/net/natLib.java +++ b/source/de/anomic/net/natLib.java @@ -45,6 +45,7 @@ package de.anomic.net; import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import de.anomic.http.httpc; @@ -143,6 +144,23 @@ public class natLib { if (ip.indexOf(":") >= 0) return false; // ipv6... return (isNotLocal(ip)) && (isIP(ip)); } + + public static final InetAddress getInetAddress(String ip) { + if (ip == null) return null; + if (ip.length() < 8) return null; + String[] ips = ip.split("\\."); + if (ips.length != 4) return null; + byte[] ipb = new byte[4]; + ipb[0] = (byte) Integer.parseInt(ips[0]); + ipb[1] = (byte) Integer.parseInt(ips[1]); + ipb[2] = (byte) Integer.parseInt(ips[2]); + ipb[3] = (byte) Integer.parseInt(ips[3]); + try { + return InetAddress.getByAddress(ipb); + } catch (UnknownHostException e) { + return null; + } + } private static int retrieveOptions() { return 3; diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index d01d9bf0a..4c57e30a5 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -2239,6 +2239,8 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser Long trackerHandle = new Long(System.currentTimeMillis()); HashMap searchProfile = theSearch.resultProfile(); searchProfile.put("host", client); + searchProfile.put("offset", new Integer(0)); + searchProfile.put("results", results); this.localSearches.put(trackerHandle, searchProfile); TreeSet handles = (TreeSet) this.localSearchTracker.get(client); if (handles == null) handles = new TreeSet(); diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 585f971ee..0dd74f1b8 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -64,7 +64,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -362,21 +361,7 @@ public class yacySeed { public final InetAddress getInetAddress() { // returns the ip address - String ip = (String) this.dna.get(yacySeed.IP); - if (ip == null) return null; - if (ip.length() < 8) return null; - String[] ips = ip.split("\\."); - if (ips.length != 4) return null; - byte[] ipb = new byte[4]; - ipb[0] = (byte) Integer.parseInt(ips[0]); - ipb[1] = (byte) Integer.parseInt(ips[1]); - ipb[2] = (byte) Integer.parseInt(ips[2]); - ipb[3] = (byte) Integer.parseInt(ips[3]); - try { - return InetAddress.getByAddress(ipb); - } catch (UnknownHostException e) { - return null; - } + return natLib.getInetAddress((String) this.dna.get(yacySeed.IP)); } public final int getPort() {