From 8e0b2c583254b03a3f424e37829dfa687ba5d859 Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 23 Nov 2011 22:21:14 +0000 Subject: [PATCH] fixed cluster search git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@8083 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacy/search.java | 26 ++++++++++++------- htroot/yacysearch.java | 22 +++++----------- source/net/yacy/peers/Protocol.java | 4 ++- source/net/yacy/search/query/SearchEvent.java | 2 +- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index f06994f95..ec404b239 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -85,7 +85,16 @@ public final class search { sb.remoteSearchLastAccess = System.currentTimeMillis(); final serverObjects prop = new serverObjects(); - if ((post == null) || (env == null)) return prop; + // set nice default values for error cases + prop.put("searchtime", "0"); + prop.put("references", ""); + prop.put("joincount", "0"); + prop.put("linkcount", "0"); + prop.put("links", ""); + prop.put("indexcount", ""); + prop.put("indexabstract", ""); + + if (post == null || env == null) return prop; if (!Protocol.authentifyRequest(post, env)) return prop; final String client = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); @@ -101,7 +110,7 @@ public final class search { // final String fwdep = post.get("fwdep", ""); // forward depth. if "0" then peer may NOT ask another peer for more results // final String fwden = post.get("fwden", ""); // forward deny, a list of seed hashes. They may NOT be target of forward hopping final int count = Math.min((int) sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_DEFAULT, 100), post.getInt("count", 10)); // maximum number of wanted results - final long maxtime = Math.min((int) sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000), post.getLong("time", 3000)); // maximum number of wanted results + final long maxtime = Math.min((int) sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000), post.getLong("time", 3000)); // maximum waiting time final int maxdist= post.getInt("maxdist", Integer.MAX_VALUE); final String prefer = post.get("prefer", ""); final String contentdom = post.get("contentdom", "text"); @@ -144,9 +153,6 @@ public final class search { if (sb.isRobinsonMode() && !sb.isPublicRobinson()) { // if we are a robinson cluster, answer only if this client is known by our network definition - prop.put("links", ""); - prop.put("linkcount", "0"); - prop.put("references", ""); return prop; } @@ -158,19 +164,19 @@ public final class search { if (trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 3000)).size() > 1) { block = true; } + } + if (!block) synchronized (trackerHandles) { if (trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 60000)).size() > 12) { block = true; } + } + if (!block) synchronized (trackerHandles) { if (trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 600000)).size() > 36) { block = true; } } - if (block && Domains.isLocal(client, null)) block = false; + if (block && Domains.isLocal(client, null)) block = false; // check isLocal here to prevent dns lookup for client if (block) { - prop.put("links", ""); - prop.put("linkcount", "0"); - prop.put("references", ""); - prop.put("searchtime", "0"); return prop; } diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index f31f52e66..0a913b540 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -207,16 +207,9 @@ public class yacysearch { } // SEARCH - final boolean indexReceiveGranted = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true) || - sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true); - global = global && indexReceiveGranted; // if the user does not want indexes from remote peers, it cannot be a global search - - final boolean clustersearch = sb.isRobinsonMode() && - (sb.getConfig("cluster.mode", "").equals("privatecluster") || - sb.getConfig("cluster.mode", "").equals("publiccluster")); - if (clustersearch) { - global = true; - } // switches search on, but search target is limited to cluster nodes + final boolean clustersearch = sb.isRobinsonMode() && (sb.getConfig("cluster.mode", "").equals("privatecluster") || sb.getConfig("cluster.mode", "").equals("publiccluster")); + final boolean indexReceiveGranted = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true) || sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true) || clustersearch; + global = global && indexReceiveGranted; // if the user does not want indexes from remote peers, it cannot be a global searchnn // increase search statistic counter if (!global) { @@ -542,9 +535,6 @@ public class yacysearch { } } - // prepare search properties - final boolean globalsearch = (global) && indexReceiveGranted; - // do the search final HandleSet queryHashes = Word.words2hashesHandles(query[0]); final Pattern snippetPattern = QueryParams.stringSearchPattern(originalquerystring); @@ -584,8 +574,8 @@ public class yacysearch { itemsPerPage, offset, urlmask, - (clustersearch && globalsearch) ? QueryParams.Searchdom.CLUSTER : - ((globalsearch) ? QueryParams.Searchdom.GLOBAL : QueryParams.Searchdom.LOCAL), + clustersearch && global ? QueryParams.Searchdom.CLUSTER : + (global && indexReceiveGranted ? QueryParams.Searchdom.GLOBAL : QueryParams.Searchdom.LOCAL), 20, constraint, true, @@ -715,7 +705,7 @@ public class yacysearch { prop.put("num-results_itemscount", Formatter.number(0, true)); prop.put("num-results_itemsPerPage", itemsPerPage); prop.put("num-results_totalcount", Formatter.number(indexcount, true)); - prop.put("num-results_globalresults", (globalsearch) ? "1" : "0"); + prop.put("num-results_globalresults", global && (indexReceiveGranted || clustersearch) ? "1" : "0"); prop.put("num-results_globalresults_localResourceSize", Formatter.number(theSearch.getRankingResult().getLocalIndexCount(), true)); prop.put("num-results_globalresults_localMissCount", Formatter.number(theSearch.getRankingResult().getMissCount(), true)); prop.put("num-results_globalresults_remoteResourceSize", Formatter.number(theSearch.getRankingResult().getRemoteResourceSize(), true)); diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.java index 621f53ce4..2bed8d4f2 100644 --- a/source/net/yacy/peers/Protocol.java +++ b/source/net/yacy/peers/Protocol.java @@ -651,12 +651,14 @@ public final class Protocol { final boolean global, final int partitions, final String hostname, - final String hostaddress, + String hostaddress, final SearchEvent.SecondarySearchSuperviser secondarySearchSuperviser, final RankingProfile rankingProfile, final Bitfield constraint) throws IOException { // send a search request to peer with remote Hash + //if (hostaddress.equals(mySeed.getClusterAddress())) hostaddress = "127.0.0.1:" + mySeed.getPort(); // for debugging + // INPUT: // iam : complete seed of the requesting peer // youare : seed hash of the target peer, used for testing network stability diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.java index 895b962b9..41c28226e 100644 --- a/source/net/yacy/search/query/SearchEvent.java +++ b/source/net/yacy/search/query/SearchEvent.java @@ -115,7 +115,7 @@ public final class SearchEvent { this.IAneardhthash = null; this.localSearchThread = null; this.order = new ReferenceOrder(this.query.ranking, UTF8.getBytes(this.query.targetlang)); - final boolean remote = (this.query.domType == QueryParams.Searchdom.GLOBAL || this.query.domType == QueryParams.Searchdom.CLUSTER) && peers.sizeConnected() > 0 && peers.mySeed().getFlagAcceptRemoteIndex(); + final boolean remote = peers.sizeConnected() > 0 && (this.query.domType == QueryParams.Searchdom.CLUSTER || (this.query.domType == QueryParams.Searchdom.GLOBAL && peers.mySeed().getFlagAcceptRemoteIndex())); final long start = System.currentTimeMillis(); if (remote) { // initialize a ranking process that is the target for data