diff options
| author | stbrumm <stbrumm@sabayon> | 2012-01-03 17:49:37 +0100 |
|---|---|---|
| committer | Michael Christen <mc@yacy.net> | 2012-01-03 17:49:37 +0100 |
| commit | d18095dc481930512fb21618806e55026d043619 (patch) | |
| tree | 77ebbaf086ef5834353e65e10226a75a0ebb3e3c /htroot | |
| parent | 9f1b1b4604662568409316890cb06f082457cf69 (diff) | |
Patch fuer Issue 0000102
and fixes to Patch (private peer status is a property of a peer, not a
status)
Diffstat (limited to 'htroot')
| -rw-r--r-- | htroot/Banner.java | 99 | ||||
| -rw-r--r-- | htroot/ConfigNetwork_p.html | 22 | ||||
| -rw-r--r-- | htroot/ConfigNetwork_p.java | 130 | ||||
| -rw-r--r-- | htroot/Status.html | 6 | ||||
| -rw-r--r-- | htroot/Status.java | 179 | ||||
| -rw-r--r-- | htroot/yacysearch.java | 639 |
6 files changed, 686 insertions, 389 deletions
diff --git a/htroot/Banner.java b/htroot/Banner.java index 8b95d6ea4..989ce21f8 100644 --- a/htroot/Banner.java +++ b/htroot/Banner.java @@ -41,18 +41,22 @@ import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; /** draw a banner with information about the peer */ -public class Banner { +public class Banner +{ - public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws IOException { + public static RasterPlotter respond( + final RequestHeader header, + final serverObjects post, + final serverSwitch env) throws IOException { final Switchboard sb = (Switchboard) env; final String IMAGE = "htroot/env/grafics/yacy.png"; int width = 468; int height = 60; - String bgcolor = "e7effc"; - String textcolor = "000000"; + String bgcolor = "e7effc"; + String textcolor = "000000"; String bordercolor = "5090d0"; - if (post != null) { + if ( post != null ) { bgcolor = post.get("bgcolor", bgcolor); textcolor = post.get("textcolor", textcolor); bordercolor = post.get("bordercolor", bordercolor); @@ -60,41 +64,41 @@ public class Banner { height = post.getInt("heigth", height); } - String name = ""; - long links = 0; - long words = 0; - int myppm = 0; - double myqph = 0; - String type = ""; + String name = ""; + long links = 0; + long words = 0; + int myppm = 0; + double myqph = 0; + String type = ""; final String network = env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified").toUpperCase(); - final int peers = sb.peers.sizeConnected() + 1; // the '+ 1': the own peer is not included in sizeConnected() - long nlinks = sb.peers.countActiveURL(); - long nwords = sb.peers.countActiveRWI(); - final double nqpm = sb.peers.countActiveQPM(); - long nppm = sb.peers.countActivePPM(); - double nqph = 0; + final int peers = sb.peers.sizeConnected() + 1; // the '+ 1': the own peer is not included in sizeConnected() + long nlinks = sb.peers.countActiveURL(); + long nwords = sb.peers.countActiveRWI(); + final double nqpm = sb.peers.countActiveQPM(); + long nppm = sb.peers.countActivePPM(); + double nqph = 0; final Seed seed = sb.peers.mySeed(); - if (seed != null){ - name = seed.get(Seed.NAME, "-").toUpperCase(); - links = seed.getLinkCount(); - words = seed.getWordCount(); - myppm = seed.getPPM(); - myqph = 60d * seed.getQPM(); + if ( seed != null ) { + name = seed.get(Seed.NAME, "-").toUpperCase(); + links = seed.getLinkCount(); + words = seed.getWordCount(); + myppm = seed.getPPM(); + myqph = 60d * seed.getQPM(); - if (sb.peers.mySeed().isVirgin()) { + if ( sb.peers.mySeed().isVirgin() ) { type = "VIRGIN"; nqph = Math.round(6000d * nqpm) / 100d; - } else if(sb.peers.mySeed().isJunior()) { + } else if ( sb.peers.mySeed().isJunior() ) { type = "JUNIOR"; nqph = Math.round(6000d * nqpm) / 100d; - } else if(sb.peers.mySeed().isSenior()) { + } else if ( sb.peers.mySeed().isSenior() ) { type = "SENIOR"; nlinks = nlinks + links; nwords = nwords + words; nqph = Math.round(6000d * nqpm + 100d * myqph) / 100d; nppm = nppm + myppm; - } else if(sb.peers.mySeed().isPrincipal()) { + } else if ( sb.peers.mySeed().isPrincipal() ) { type = "PRINCIPAL"; nlinks = nlinks + links; nwords = nwords + words; @@ -103,13 +107,48 @@ public class Banner { } } - if (!NetworkGraph.logoIsLoaded()) { + if ( !NetworkGraph.logoIsLoaded() ) { ImageIO.setUseCache(false); // do not write a cache to disc; keep in RAM final BufferedImage logo = ImageIO.read(new File(IMAGE)); - return NetworkGraph.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, peers, nlinks, nwords, nqph, nppm, logo); + return NetworkGraph.getBannerPicture( + 1000, + width, + height, + bgcolor, + textcolor, + bordercolor, + name, + links, + words, + type, + myppm, + network, + peers, + nlinks, + nwords, + nqph, + nppm, + logo); } - return NetworkGraph.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, peers, nlinks, nwords, nqph, nppm); + return NetworkGraph.getBannerPicture( + 1000, + width, + height, + bgcolor, + textcolor, + bordercolor, + name, + links, + words, + type, + myppm, + network, + peers, + nlinks, + nwords, + nqph, + nppm); } } diff --git a/htroot/ConfigNetwork_p.html b/htroot/ConfigNetwork_p.html index 08be1457b..decb0e96e 100644 --- a/htroot/ConfigNetwork_p.html +++ b/htroot/ConfigNetwork_p.html @@ -163,23 +163,9 @@ </dt> <dd>Your search engine will not contact any other peer, and will reject every request. </dd> - <!-- not yet implemented <dt> - <label for="cluster.modePrivatecluster">Private Cluster</label> - <input type="radio" value="privatecluster" id="cluster.modePrivatecluster" name="cluster.mode" - #(privateclusterChecked)#::checked="checked" #(/privateclusterChecked)#/> - </dt> - <dd> - Your peer is part of a private cluster without public visibility.<br /> - Index data is not distributed, but remote crawl requests are distributed and accepted from your cluster.<br /> - Search requests are spread over all peers of the cluster, and answered from all peers of the cluster.<br /> - List of ip:port - addresses of the cluster: (comma-separated)<br /> - <input type="text" name="cluster.peers.ipport" value="#[cluster.peers.ipport]#" size="80" maxlength="800" /> - </dd> - --> - <dt> - <label for="cluster.modePublicpeer">Public Peer</label> - <input type="radio" value="publicpeer" id="cluster.modePublicpeer" name="cluster.mode" + <label for="publicpeer">Public Peer</label> + <input type="radio" value="publicpeer" id="publicpeer" name="cluster.mode" #(publicpeerChecked)#::checked="checked" #(/publicpeerChecked)#/> </dt> <dd> @@ -187,8 +173,8 @@ Your peer does not accept any outside index data, but responds on all remote search requests. </dd> <dt> - <label for="cluster.modePubliccluster">Public Cluster</label> - <input type="radio" value="publiccluster" id="cluster.modePubliccluster" name="cluster.mode" + <label for="publiccluster">Public Cluster</label> + <input type="radio" value="publiccluster" id="publiccluster" name="cluster.mode" #(publicclusterChecked)#::checked="checked" #(/publicclusterChecked)#/> </dt> <dd> diff --git a/htroot/ConfigNetwork_p.java b/htroot/ConfigNetwork_p.java index 5c6086165..e78ab69d0 100644 --- a/htroot/ConfigNetwork_p.java +++ b/htroot/ConfigNetwork_p.java @@ -40,26 +40,36 @@ import de.anomic.data.WorkTables; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; -public class ConfigNetwork_p { +public class ConfigNetwork_p +{ - public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws FileNotFoundException, IOException { + public static serverObjects respond( + final RequestHeader header, + final serverObjects post, + final serverSwitch env) throws FileNotFoundException, IOException { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); int commit = 0; // load all options for network definitions - final File networkBootstrapLocationsFile = new File(new File(sb.getAppPath(), "defaults"), "yacy.networks"); + final File networkBootstrapLocationsFile = + new File(new File(sb.getAppPath(), "defaults"), "yacy.networks"); final Set<String> networkBootstrapLocations = FileUtils.loadList(networkBootstrapLocationsFile); - if (post != null) { + if ( post != null ) { // store this call as api call - sb.tables.recordAPICall(post, "ConfigNetwork_p.html", WorkTables.TABLE_API_TYPE_CONFIGURATION, "network settings"); - - if (post.containsKey("changeNetwork")) { - final String networkDefinition = post.get("networkDefinition", "defaults/yacy.network.freeworld.unit"); - if (networkDefinition.equals(sb.getConfig("network.unit.definition", ""))) { + sb.tables.recordAPICall( + post, + "ConfigNetwork_p.html", + WorkTables.TABLE_API_TYPE_CONFIGURATION, + "network settings"); + + if ( post.containsKey("changeNetwork") ) { + final String networkDefinition = + post.get("networkDefinition", "defaults/yacy.network.freeworld.unit"); + if ( networkDefinition.equals(sb.getConfig("network.unit.definition", "")) ) { // no change commit = 3; } else { @@ -69,55 +79,55 @@ public class ConfigNetwork_p { } } - if (post.containsKey("save")) { + if ( post.containsKey("save") ) { // DHT control boolean indexDistribute = "on".equals(post.get("indexDistribute", "")); boolean indexReceive = "on".equals(post.get("indexReceive", "")); - if (!indexReceive) { + if ( !indexReceive ) { // remove heuristics sb.setConfig("heuristic.site", false); sb.setConfig("heuristic.scroogle", false); sb.setConfig("heuristic.blekko", false); } final boolean robinsonmode = "robinson".equals(post.get("network", "")); - if (robinsonmode) { + if ( robinsonmode ) { indexDistribute = false; indexReceive = false; commit = 1; } else { - if (!indexDistribute && !indexReceive) { + if ( !indexDistribute && !indexReceive ) { prop.put("commitDHTIsRobinson", "1"); commit = 2; - } else if (indexDistribute && indexReceive) { + } else if ( indexDistribute && indexReceive ) { commit = 1; } else { - if (!indexReceive) { + if ( !indexReceive ) { prop.put("commitDHTNoGlobalSearch", "1"); } commit = 1; } } - if (indexDistribute) { + if ( indexDistribute ) { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, true); } else { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, false); } - if ("on".equals(post.get("indexDistributeWhileCrawling",""))) { + if ( "on".equals(post.get("indexDistributeWhileCrawling", "")) ) { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true); } else { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, false); } - if ("on".equals(post.get("indexDistributeWhileIndexing",""))) { + if ( "on".equals(post.get("indexDistributeWhileIndexing", "")) ) { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true); } else { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, false); } - if (indexReceive) { + if ( indexReceive ) { sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true); sb.peers.mySeed().setFlagAcceptRemoteIndex(true); } else { @@ -126,19 +136,24 @@ public class ConfigNetwork_p { sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, false); } - if ("on".equals(post.get("indexReceiveBlockBlacklist", ""))) { + if ( "on".equals(post.get("indexReceiveBlockBlacklist", "")) ) { sb.setConfig("indexReceiveBlockBlacklist", true); } else { sb.setConfig("indexReceiveBlockBlacklist", false); } - if (post.containsKey("peertags")) { - sb.peers.mySeed().setPeerTags(MapTools.string2set(normalizedList(post.get("peertags")), ",")); + if ( post.containsKey("peertags") ) { + sb.peers.mySeed().setPeerTags( + MapTools.string2set(normalizedList(post.get("peertags")), ",")); } - sb.setConfig("cluster.mode", post.get("cluster.mode", "publicpeer")); + sb.setConfig("cluster.mode", post.get( + SwitchboardConstants.CLUSTER_MODE, + SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER)); sb.setConfig("cluster.peers.ipport", checkIPPortList(post.get("cluster.peers.ipport", ""))); - sb.setConfig("cluster.peers.yacydomain", checkYaCyDomainList(post.get("cluster.peers.yacydomain", ""))); + sb.setConfig( + "cluster.peers.yacydomain", + checkYaCyDomainList(post.get("cluster.peers.yacydomain", ""))); // update the cluster hash set sb.clusterhashes = sb.peers.clusterHashes(sb.getConfig("cluster.peers.yacydomain", "")); @@ -150,20 +165,34 @@ public class ConfigNetwork_p { // write remote crawl request settings prop.put("crawlResponse", sb.getConfigBool("crawlResponse", false) ? "1" : "0"); - final long RTCbusySleep = Math.max(1, env.getConfigInt(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, 100)); + final long RTCbusySleep = + Math + .max(1, env.getConfigInt(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, 100)); final int RTCppm = (int) (60000L / RTCbusySleep); prop.put("acceptCrawlLimit", RTCppm); final boolean indexDistribute = sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, true); final boolean indexReceive = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true); prop.put("indexDistributeChecked", (indexDistribute) ? "1" : "0"); - prop.put("indexDistributeWhileCrawling.on", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "1" : "0"); - prop.put("indexDistributeWhileCrawling.off", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "0" : "1"); - prop.put("indexDistributeWhileIndexing.on", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "1" : "0"); - prop.put("indexDistributeWhileIndexing.off", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "0" : "1"); + prop.put( + "indexDistributeWhileCrawling.on", + (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "1" : "0"); + prop.put( + "indexDistributeWhileCrawling.off", + (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "0" : "1"); + prop.put( + "indexDistributeWhileIndexing.on", + (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "1" : "0"); + prop.put( + "indexDistributeWhileIndexing.off", + (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "0" : "1"); prop.put("indexReceiveChecked", (indexReceive) ? "1" : "0"); - prop.put("indexReceiveBlockBlacklistChecked.on", (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "1" : "0"); - prop.put("indexReceiveBlockBlacklistChecked.off", (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "0" : "1"); + prop.put( + "indexReceiveBlockBlacklistChecked.on", + (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "1" : "0"); + prop.put( + "indexReceiveBlockBlacklistChecked.off", + (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "0" : "1"); prop.putHTML("peertags", MapTools.set2string(sb.peers.mySeed().getPeerTags(), ",", false)); // set seed information directly @@ -176,20 +205,25 @@ public class ConfigNetwork_p { prop.putHTML("cluster.peers.ipport", sb.getConfig("cluster.peers.ipport", "")); prop.putHTML("cluster.peers.yacydomain", sb.getConfig("cluster.peers.yacydomain", "")); StringBuilder hashes = new StringBuilder(); - for (final byte[] h : sb.clusterhashes.keySet()) { + for ( final byte[] h : sb.clusterhashes.keySet() ) { hashes.append(", ").append(ASCII.String(h)); } - if (hashes.length() > 2) { + if ( hashes.length() > 2 ) { hashes = hashes.delete(0, 2); } prop.put("cluster.peers.yacydomain.hashes", hashes.toString()); // set p2p mode flags - prop.put("privatepeerChecked", ("privatepeer".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); - prop.put("privateclusterChecked", ("privatecluster".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); - prop.put("publicclusterChecked", ("publiccluster".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); - prop.put("publicpeerChecked", ("publicpeer".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); + prop.put( + "privatepeerChecked", + (SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) ? "1" : "0"); + prop.put( + "publicclusterChecked", + (SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) ? "1" : "0"); + prop.put( + "publicpeerChecked", + (SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) ? "1" : "0"); // set network configuration prop.putHTML("network.unit.definition", sb.getConfig("network.unit.definition", "")); @@ -199,7 +233,7 @@ public class ConfigNetwork_p { prop.putHTML("network.unit.dht", sb.getConfig("network.unit.dht", "")); networkBootstrapLocations.remove(sb.getConfig("network.unit.definition", "")); int c = 0; - for (final String s: networkBootstrapLocations) { + for ( final String s : networkBootstrapLocations ) { prop.put("networks_" + c++ + "_network", s); } prop.put("networks", c); @@ -211,10 +245,10 @@ public class ConfigNetwork_p { input = input.replace(' ', ','); input = input.replace(' ', ';'); input = input.replaceAll(",,", ","); - if (input.length() > 0 && input.charAt(0) == ',') { + if ( input.length() > 0 && input.charAt(0) == ',' ) { input = input.substring(1); } - if (input.endsWith(",")) { + if ( input.endsWith(",") ) { input = input.substring(0, input.length() - 1); } return input; @@ -223,14 +257,16 @@ public class ConfigNetwork_p { private static String checkYaCyDomainList(final String input) { final String[] array = normalizedList(input).split(","); final StringBuilder output = new StringBuilder(); - for (final String element : array) { - if ((element.endsWith(".yacyh")) || (element.endsWith(".yacy")) || - (element.indexOf(".yacyh=",0) > 0) || (element.indexOf(".yacy=",0) > 0)) { + for ( final String element : array ) { + if ( (element.endsWith(".yacyh")) + || (element.endsWith(".yacy")) + || (element.indexOf(".yacyh=", 0) > 0) + || (element.indexOf(".yacy=", 0) > 0) ) { output.append(",").append(element); } } - if (output.length() == 0) { + if ( output.length() == 0 ) { return input; } return output.delete(0, 1).toString(); @@ -239,12 +275,12 @@ public class ConfigNetwork_p { private static String checkIPPortList(final String input) { final String[] array = normalizedList(input).split(","); final StringBuilder output = new StringBuilder(); - for (final String element :array) { - if (element.indexOf(':',0) >= 9) { + for ( final String element : array ) { + if ( element.indexOf(':', 0) >= 9 ) { output.append(",").append(element); } } - if (input.length() == 0) { + if ( input.length() == 0 ) { return input; } return output.delete(0, 1).toString(); diff --git a/htroot/Status.html b/htroot/Status.html index a1091e970..9a64059f6 100644 --- a/htroot/Status.html +++ b/htroot/Status.html @@ -69,6 +69,12 @@ <dd class="hint">You have not published your peer seed yet. This happens automatically, just wait.
</dd>
#(/urgentStatusVirgin)#
+
+ #(hintStatusPrivate)#::
+ <dt class="hintIcon"><img src="env/grafics/bad.png" width="32" height="32" alt="idea"/></dt>
+ <dd class="hint">Your network configuration is in private mode. Your peer seed will not be published.
+ </dd>
+ #(/hintStatusPrivate)#
<!-- warnings -->
diff --git a/htroot/Status.java b/htroot/Status.java index 36e359039..ab9243c60 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -46,67 +46,73 @@ import de.anomic.server.serverCore; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
-public class Status {
+public class Status
+{
private static final String SEEDSERVER = "seedServer";
private static final String PEERSTATUS = "peerStatus";
- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ public static serverObjects respond(
+ final RequestHeader header,
+ final serverObjects post,
+ final serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
// check if the basic configuration was accessed before and forward
prop.put("forwardToConfigBasic", 0);
- if ((post == null || !post.containsKey("noforward")) &&
- sb.getConfig("server.servlets.submitted", "").indexOf("ConfigBasic.html",0) < 0 &&
- Seed.isDefaultPeerName(sb.peers.mySeed().getName())) {
+ if ( (post == null || !post.containsKey("noforward"))
+ && sb.getConfig("server.servlets.submitted", "").indexOf("ConfigBasic.html", 0) < 0
+ && Seed.isDefaultPeerName(sb.peers.mySeed().getName()) ) {
// forward to ConfigBasic
prop.put("forwardToConfigBasic", 1);
}
- if (post != null) post.remove("noforward");
+ if ( post != null ) {
+ post.remove("noforward");
+ }
- if (post != null && post.size() > 0) {
- if (sb.adminAuthenticated(header) < 2) {
- prop.put("AUTHENTICATE","admin log-in");
+ if ( post != null && post.size() > 0 ) {
+ if ( sb.adminAuthenticated(header) < 2 ) {
+ prop.put("AUTHENTICATE", "admin log-in");
return prop;
}
boolean redirect = false;
- if (post.containsKey("login")) {
- prop.put("LOCATION","");
+ if ( post.containsKey("login") ) {
+ prop.put("LOCATION", "");
return prop;
- } else if (post.containsKey("pauseCrawlJob")) {
+ } else if ( post.containsKey("pauseCrawlJob") ) {
final String jobType = post.get("jobType");
- if ("localCrawl".equals(jobType)) {
+ if ( "localCrawl".equals(jobType) ) {
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- } else if ("remoteTriggeredCrawl".equals(jobType)) {
+ } else if ( "remoteTriggeredCrawl".equals(jobType) ) {
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
redirect = true;
- } else if (post.containsKey("continueCrawlJob")) {
+ } else if ( post.containsKey("continueCrawlJob") ) {
final String jobType = post.get("jobType");
- if ("localCrawl".equals(jobType)) {
+ if ( "localCrawl".equals(jobType) ) {
sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- } else if ("remoteTriggeredCrawl".equals(jobType)) {
+ } else if ( "remoteTriggeredCrawl".equals(jobType) ) {
sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
redirect = true;
- } else if (post.containsKey("ResetTraffic")) {
+ } else if ( post.containsKey("ResetTraffic") ) {
ByteCount.resetCount();
redirect = true;
- } else if (post.containsKey("popup")) {
+ } else if ( post.containsKey("popup") ) {
final boolean trigger_enabled = post.getBoolean("popup", false);
sb.setConfig("browserPopUpTrigger", trigger_enabled);
redirect = true;
- } else if (post.containsKey("tray")) {
+ } else if ( post.containsKey("tray") ) {
final boolean trigger_enabled = post.getBoolean("tray", false);
sb.setConfig("trayIcon", trigger_enabled);
redirect = true;
}
- if (redirect) {
- prop.put("LOCATION","");
- return prop;
+ if ( redirect ) {
+ prop.put("LOCATION", "");
+ return prop;
}
}
@@ -114,7 +120,7 @@ public class Status { sb.updateMySeed();
final boolean adminaccess = sb.adminAuthenticated(header) >= 2;
- if (adminaccess) {
+ if ( adminaccess ) {
prop.put("showPrivateTable", "1");
prop.put("privateStatusTable", "Status_p.inc");
} else {
@@ -123,26 +129,28 @@ public class Status { }
// password protection
- if ((sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0) && (!sb.getConfigBool("adminAccountForLocalhost", false))) {
+ if ( (sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0)
+ && (!sb.getConfigBool("adminAccountForLocalhost", false)) ) {
prop.put("protection", "0"); // not protected
prop.put("urgentSetPassword", "1");
} else {
prop.put("protection", "1"); // protected
}
- if (sb.getConfigBool("adminAccountForLocalhost", false)) {
+ if ( sb.getConfigBool("adminAccountForLocalhost", false) ) {
prop.put("unrestrictedLocalAccess", 1);
}
// resource observer status
- if (adminaccess) {
- if (!sb.observer.getDiskAvailable()){
+ if ( adminaccess ) {
+ if ( !sb.observer.getDiskAvailable() ) {
final String minFree = Formatter.bytesToString(sb.observer.getMinFreeDiskSpace());
prop.put("warningDiskSpaceLow", "1");
prop.put("warningDiskSpaceLow_minSpace", minFree);
}
- if (!sb.observer.getMemoryAvailable()){
- final String minFree = Formatter.bytesToString(sb.observer.getMinFreeMemory() * 1024L * 1024L);
+ if ( !sb.observer.getMemoryAvailable() ) {
+ final String minFree =
+ Formatter.bytesToString(sb.observer.getMinFreeMemory() * 1024L * 1024L);
prop.put("warningMemoryLow", "1");
prop.put("warningMemoryLow_minSpace", minFree);
}
@@ -151,25 +159,26 @@ public class Status { // version information
//final String versionstring = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1"));
- final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();
+ final String versionstring =
+ yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();
prop.put("versionpp", versionstring);
// place some more hints
- if ((adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() == 0)) {
+ if ( (adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() == 0) ) {
prop.put("hintCrawlStart", "1");
}
- if ((adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() > 500)) {
+ if ( (adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() > 500) ) {
prop.put("hintCrawlMonitor", "1");
}
// hostname and port
final String extendedPortString = sb.getConfig("port", "8090");
- final int pos = extendedPortString.indexOf(':',0);
- prop.put("port",serverCore.getPortNr(extendedPortString));
- if (pos != -1) {
+ final int pos = extendedPortString.indexOf(':', 0);
+ prop.put("port", serverCore.getPortNr(extendedPortString));
+ if ( pos != -1 ) {
prop.put("extPortFormat", "1");
- prop.putHTML("extPortFormat_extPort",extendedPortString);
+ prop.putHTML("extPortFormat_extPort", extendedPortString);
} else {
prop.put("extPortFormat", "0");
}
@@ -177,9 +186,9 @@ public class Status { prop.put("host", hostIP != null ? hostIP.getHostAddress() : "Unkown IP");
// ssl support
- prop.put("sslSupport",sb.getConfig("keyStore", "").length() == 0 ? "0" : "1");
+ prop.put("sslSupport", sb.getConfig("keyStore", "").length() == 0 ? "0" : "1");
- if (sb.getConfigBool("remoteProxyUse", false)) {
+ if ( sb.getConfigBool("remoteProxyUse", false) ) {
prop.put("remoteProxy", "1");
prop.putXML("remoteProxy_host", sb.getConfig("remoteProxyHost", "<unknown>"));
prop.putXML("remoteProxy_port", sb.getConfig("remoteProxyPort", "<unknown>"));
@@ -191,22 +200,24 @@ public class Status { // peer information
String thisHash = "";
final String thisName = sb.peers.mySeed().getName();
- if (sb.peers.mySeed() == null) {
+ if ( sb.peers.mySeed() == null ) {
thisHash = "not assigned";
- prop.put("peerAddress", "0"); // not assigned
+ prop.put("peerAddress", "0"); // not assigned
prop.put("peerStatistics", "0"); // unknown
} else {
final long uptime = 60000 * sb.peers.mySeed().getLong(Seed.UPTIME, 0L);
prop.put("peerStatistics", "1");
prop.put("peerStatistics_uptime", PeerActions.formatInterval(uptime));
prop.putNum("peerStatistics_pagesperminute", sb.peers.mySeed().getPPM());
- prop.putNum("peerStatistics_queriesperhour", Math.round(6000d * sb.peers.mySeed().getQPM()) / 100d);
+ prop.putNum(
+ "peerStatistics_queriesperhour",
+ Math.round(6000d * sb.peers.mySeed().getQPM()) / 100d);
prop.putNum("peerStatistics_links", sb.peers.mySeed().getLinkCount());
prop.put("peerStatistics_words", Formatter.number(sb.peers.mySeed().getWordCount()));
prop.putNum("peerStatistics_disconnects", sb.peers.peerActions.disconnects);
prop.put("peerStatistics_connects", Formatter.number(sb.peers.mySeed().get(Seed.CCOUNT, "0")));
thisHash = sb.peers.mySeed().hash;
- if (sb.peers.mySeed().getPublicAddress() == null) {
+ if ( sb.peers.mySeed().getPublicAddress() == null ) {
prop.put("peerAddress", "0"); // not assigned + instructions
prop.put("warningGoOnline", "1");
} else {
@@ -215,17 +226,25 @@ public class Status { prop.putXML("peerAddress_peername", sb.peers.mySeed().getName().toLowerCase());
}
}
- final String peerStatus = ((sb.peers.mySeed() == null) ? Seed.PEERTYPE_VIRGIN : sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN));
- if (Seed.PEERTYPE_VIRGIN.equals(peerStatus) && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))) {
+ final String peerStatus =
+ ((sb.peers.mySeed() == null) ? Seed.PEERTYPE_VIRGIN : sb.peers.mySeed().get(
+ Seed.PEERTYPE,
+ Seed.PEERTYPE_VIRGIN));
+
+ if ( Seed.PEERTYPE_VIRGIN.equals(peerStatus)
+ && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))
+ && !SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) {
prop.put(PEERSTATUS, "0");
prop.put("urgentStatusVirgin", "1");
- } else if (Seed.PEERTYPE_JUNIOR.equals(peerStatus) && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))) {
+ } else if ( Seed.PEERTYPE_JUNIOR.equals(peerStatus)
+ && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))
+ && !SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) {
prop.put(PEERSTATUS, "1");
prop.put("warningStatusJunior", "1");
- } else if (Seed.PEERTYPE_SENIOR.equals(peerStatus)) {
+ } else if ( Seed.PEERTYPE_SENIOR.equals(peerStatus) ) {
prop.put(PEERSTATUS, "2");
prop.put("hintStatusSenior", "1");
- } else if (Seed.PEERTYPE_PRINCIPAL.equals(peerStatus)) {
+ } else if ( Seed.PEERTYPE_PRINCIPAL.equals(peerStatus) ) {
prop.put(PEERSTATUS, "3");
prop.put("hintStatusPrincipal", "1");
prop.put("hintStatusPrincipal_seedURL", sb.peers.mySeed().get(Seed.SEEDLISTURL, "?"));
@@ -234,50 +253,52 @@ public class Status { prop.put("hash", thisHash);
final String seedUploadMethod = sb.getConfig("seedUploadMethod", "");
- if (!"none".equalsIgnoreCase(seedUploadMethod) ||
- ("".equals(seedUploadMethod) && (sb.getConfig("seedFTPPassword", "").length() > 0 ||
- sb.getConfig("seedFilePath", "").length() > 0))) {
- if ("".equals(seedUploadMethod)) {
- if (sb.getConfig("seedFTPPassword", "").length() > 0) {
- sb.setConfig("seedUploadMethod","Ftp");
+ if ( !"none".equalsIgnoreCase(seedUploadMethod)
+ || ("".equals(seedUploadMethod) && (sb.getConfig("seedFTPPassword", "").length() > 0 || sb
+ .getConfig("seedFilePath", "")
+ .length() > 0)) ) {
+ if ( "".equals(seedUploadMethod) ) {
+ if ( sb.getConfig("seedFTPPassword", "").length() > 0 ) {
+ sb.setConfig("seedUploadMethod", "Ftp");
}
- if (sb.getConfig("seedFilePath", "").length() > 0) {
- sb.setConfig("seedUploadMethod","File");
+ if ( sb.getConfig("seedFilePath", "").length() > 0 ) {
+ sb.setConfig("seedUploadMethod", "File");
}
}
- if ("ftp".equalsIgnoreCase(seedUploadMethod)) {
+ if ( "ftp".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "1"); // enabled
prop.putHTML("seedServer_seedServer", sb.getConfig("seedFTPServer", ""));
- } else if ("scp".equalsIgnoreCase(seedUploadMethod)) {
+ } else if ( "scp".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "1"); // enabled
prop.putHTML("seedServer_seedServer", sb.getConfig("seedScpServer", ""));
- } else if ("file".equalsIgnoreCase(seedUploadMethod)) {
+ } else if ( "file".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "2"); // enabled
prop.putHTML("seedServer_seedFile", sb.getConfig("seedFilePath", ""));
}
- prop.put("seedServer_lastUpload",
- PeerActions.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
+ prop.put(
+ "seedServer_lastUpload",
+ PeerActions.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
} else {
prop.put(SEEDSERVER, "0"); // disabled
}
- if (sb.peers != null && sb.peers.sizeConnected() > 0){
+ if ( sb.peers != null && sb.peers.sizeConnected() > 0 ) {
prop.put("otherPeers", "1");
prop.putNum("otherPeers_num", sb.peers.sizeConnected());
- }else{
+ } else {
prop.put("otherPeers", "0"); // not online
}
- if (!sb.getConfigBool("browserPopUpTrigger", false)) {
+ if ( !sb.getConfigBool("browserPopUpTrigger", false) ) {
prop.put("popup", "0");
} else {
prop.put("popup", "1");
}
- if (!OS.isWindows) {
- prop.put("tray", "2");
- } else if (!sb.getConfigBool("trayIcon", false)) {
+ if ( !OS.isWindows ) {
+ prop.put("tray", "2");
+ } else if ( !sb.getConfigBool("trayIcon", false) ) {
prop.put("tray", "0");
} else {
prop.put("tray", "1");
@@ -305,18 +326,26 @@ public class Status { final int loaderPercent = (loaderMaxCount == 0) ? 0 : loaderJobCount * 100 / loaderMaxCount;
prop.putNum("loaderQueueSize", loaderJobCount);
prop.putNum("loaderQueueMax", loaderMaxCount);
- prop.put("loaderQueuePercent", (loaderPercent>100) ? 100 : loaderPercent);
-
- prop.putNum("localCrawlQueueSize", sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount());
- prop.put("localCrawlPaused",sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL) ? "1" : "0");
-
- prop.putNum("remoteTriggeredCrawlQueueSize", sb.getThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL).getJobCount());
- prop.put("remoteTriggeredCrawlPaused",sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL) ? "1" : "0");
+ prop.put("loaderQueuePercent", (loaderPercent > 100) ? 100 : loaderPercent);
+
+ prop.putNum("localCrawlQueueSize", sb
+ .getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)
+ .getJobCount());
+ prop.put("localCrawlPaused", sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)
+ ? "1"
+ : "0");
+
+ prop.putNum(
+ "remoteTriggeredCrawlQueueSize",
+ sb.getThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL).getJobCount());
+ prop.put(
+ "remoteTriggeredCrawlPaused",
+ sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL) ? "1" : "0");
prop.putNum("stackCrawlQueueSize", sb.crawlStacker.size());
// return rewrite properties
- prop.put("date",(new Date()).toString());
+ prop.put("date", (new Date()).toString());
return prop;
}
}
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 52e78ae82..046706203 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -81,38 +81,45 @@ import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch;
import de.anomic.server.servletProperties;
-public class yacysearch {
+public class yacysearch
+{
- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ public static serverObjects respond(
+ final RequestHeader header,
+ final serverObjects post,
+ final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
sb.localSearchLastAccess = System.currentTimeMillis();
- final boolean searchAllowed = sb.getConfigBool("publicSearchpage", true) || sb.verifyAuthentication(header);
+ final boolean searchAllowed =
+ sb.getConfigBool("publicSearchpage", true) || sb.verifyAuthentication(header);
boolean authenticated = sb.adminAuthenticated(header) >= 2;
- if (!authenticated) {
+ if ( !authenticated ) {
final UserDB.Entry user = sb.userDB.getUser(header);
authenticated = (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT));
}
final boolean localhostAccess = sb.accessFromLocalhost(header);
final String promoteSearchPageGreeting =
- (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ?
- env.getConfig("network.unit.description", "") :
- env.getConfig(SwitchboardConstants.GREETING, "");
+ (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ? env.getConfig(
+ "network.unit.description",
+ "") : env.getConfig(SwitchboardConstants.GREETING, "");
final String client = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the search client who initiated the search
// get query
- final String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim();
- String querystring = originalquerystring.replace('+', ' ').replace('*', ' ').trim();
- CacheStrategy snippetFetchStrategy = (post == null) ? null : CacheStrategy.parse(post.get("verify", "cacheonly"));
+ final String originalquerystring =
+ (post == null) ? "" : post.get("query", post.get("search", "")).trim();
+ String querystring = originalquerystring.replace('+', ' ').replace('*', ' ').trim();
+ CacheStrategy snippetFetchStrategy =
+ (post == null) ? null : CacheStrategy.parse(post.get("verify", "cacheonly"));
final servletProperties prop = new servletProperties();
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
// get segment
Segment indexSegment = null;
- if (post != null && post.containsKey("segment")) {
+ if ( post != null && post.containsKey("segment") ) {
final String segmentName = post.get("segment");
- if (sb.indexSegments.segmentExist(segmentName)) {
+ if ( sb.indexSegments.segmentExist(segmentName) ) {
indexSegment = sb.indexSegments.segment(segmentName);
}
} else {
@@ -124,9 +131,13 @@ public class yacysearch { final boolean rss = EXT.equals("rss");
final boolean json = EXT.equals("json");
prop.put("promoteSearchPageGreeting", promoteSearchPageGreeting);
- prop.put("promoteSearchPageGreeting.homepage", sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
- prop.put("promoteSearchPageGreeting.smallImage", sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
- if (post == null || indexSegment == null || env == null || !searchAllowed) {
+ prop.put(
+ "promoteSearchPageGreeting.homepage",
+ sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
+ prop.put(
+ "promoteSearchPageGreeting.smallImage",
+ sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
+ if ( post == null || indexSegment == null || env == null || !searchAllowed ) {
// we create empty entries for template strings
prop.put("searchagain", "0");
prop.put("former", "");
@@ -140,8 +151,12 @@ public class yacysearch { prop.put("constraint", "");
prop.put("cat", "href");
prop.put("depth", "0");
- prop.put("search.verify", (post == null) ? sb.getConfig("search.verify", "iffresh") : post.get("verify", "iffresh"));
- prop.put("search.navigation", (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
+ prop.put(
+ "search.verify",
+ (post == null) ? sb.getConfig("search.verify", "iffresh") : post.get("verify", "iffresh"));
+ prop.put(
+ "search.navigation",
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
prop.put("contentdom", "text");
prop.put("contentdomCheckText", "1");
prop.put("contentdomCheckAudio", "0");
@@ -162,17 +177,17 @@ public class yacysearch { }
// check for JSONP
- if (post.containsKey("callback")) {
- final String jsonp = post.get("callback")+ "([";
- prop.put("jsonp-start", jsonp);
- prop.put("jsonp-end", "])");
+ if ( post.containsKey("callback") ) {
+ final String jsonp = post.get("callback") + "([";
+ prop.put("jsonp-start", jsonp);
+ prop.put("jsonp-end", "])");
} else {
- prop.put("jsonp-start", "");
- prop.put("jsonp-end", "");
+ prop.put("jsonp-start", "");
+ prop.put("jsonp-end", "");
}
// Adding CORS Access header for yacysearch.rss output
- if (rss) {
+ if ( rss ) {
final ResponseHeader outgoingHeader = new ResponseHeader();
outgoingHeader.put(HeaderFramework.CORS_ALLOW_ORIGIN, "*");
prop.setOutgoingHeader(outgoingHeader);
@@ -180,40 +195,53 @@ public class yacysearch { // collect search attributes
- int maximumRecords = Math.min((authenticated) ? (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ? 100 : 5000) : (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ? 20 : 1000), post.getInt("maximumRecords", post.getInt("count", 10))); // SRU syntax with old property as alternative
+ int maximumRecords =
+ Math.min(
+ (authenticated)
+ ? (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline()
+ ? 100
+ : 5000) : (snippetFetchStrategy != null
+ && snippetFetchStrategy.isAllowedToFetchOnline() ? 20 : 1000),
+ post.getInt("maximumRecords", post.getInt("count", 10))); // SRU syntax with old property as alternative
int startRecord = post.getInt("startRecord", post.getInt("offset", 0));
boolean global = post.get("resource", "local").equals("global") && sb.peers.sizeConnected() > 0;
- final boolean indexof = (post != null && post.get("indexof","").equals("on"));
+ final boolean indexof = (post != null && post.get("indexof", "").equals("on"));
final String originalUrlMask;
- if (post.containsKey("urlmaskfilter")) {
+ if ( post.containsKey("urlmaskfilter") ) {
originalUrlMask = post.get("urlmaskfilter", ".*");
} else {
originalUrlMask = ".*";
}
String prefermask = (post == null) ? "" : post.get("prefermaskfilter", "");
- if (!prefermask.isEmpty() && prefermask.indexOf(".*",0) < 0) {
+ if ( !prefermask.isEmpty() && prefermask.indexOf(".*", 0) < 0 ) {
prefermask = ".*" + prefermask + ".*";
}
- Bitfield constraint = (post != null && post.containsKey("constraint") && !post.get("constraint", "").isEmpty()) ? new Bitfield(4, post.get("constraint", "______")) : null;
- if (indexof) {
+ Bitfield constraint =
+ (post != null && post.containsKey("constraint") && !post.get("constraint", "").isEmpty())
+ ? new Bitfield(4, post.get("constraint", "______"))
+ : null;
+ if ( indexof ) {
constraint = new Bitfield(4);
constraint.set(Condenser.flag_cat_indexof, true);
}
// SEARCH
- 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;
+ final boolean clustersearch = sb.isRobinsonMode() && sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER);
+ 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) {
+ if ( !global ) {
// we count only searches on the local peer here, because global searches
// are counted on the target peer to preserve privacy of the searcher
- if (authenticated) {
+ if ( authenticated ) {
// local or authenticated search requests are counted separately
// because they are not part of a public available peer statistic
sb.searchQueriesRobinsonFromLocal++;
@@ -225,63 +253,102 @@ public class yacysearch { }
// find search domain
- final ContentDomain contentdom = ContentDomain.contentdomParser(post == null ? "text" : post.get("contentdom", "text"));
+ final ContentDomain contentdom =
+ ContentDomain.contentdomParser(post == null ? "text" : post.get("contentdom", "text"));
// patch until better search profiles are available
- if (contentdom == ContentDomain.TEXT) {
- if (maximumRecords > 50 && maximumRecords < 100) maximumRecords = 10;
+ if ( contentdom == ContentDomain.TEXT ) {
+ if ( maximumRecords > 50 && maximumRecords < 100 ) {
+ maximumRecords = 10;
+ }
} else {
- if (maximumRecords <= 32) maximumRecords = 64;
+ if ( maximumRecords <= 32 ) {
+ maximumRecords = 64;
+ }
}
// check the search tracker
TreeSet<Long> trackerHandles = sb.localSearchTracker.get(client);
- if (trackerHandles == null) {
+ if ( trackerHandles == null ) {
trackerHandles = new TreeSet<Long>();
}
boolean block = false;
- if (Domains.matchesList(client, sb.networkBlacklist)) {
+ if ( Domains.matchesList(client, sb.networkBlacklist) ) {
global = false;
- if (snippetFetchStrategy != null) {
+ if ( snippetFetchStrategy != null ) {
snippetFetchStrategy = null;
}
block = true;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: BLACKLISTED CLIENT FROM " + client + " gets no permission to search");
- } else if (Domains.matchesList(client, sb.networkWhitelist)) {
- Log.logInfo("LOCAL_SEARCH", "ACCESS CONTROL: WHITELISTED CLIENT FROM " + client + " gets no search restrictions");
- } else if (!authenticated && !localhostAccess) {
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: BLACKLISTED CLIENT FROM "
+ + client
+ + " gets no permission to search");
+ } else if ( Domains.matchesList(client, sb.networkWhitelist) ) {
+ Log.logInfo("LOCAL_SEARCH", "ACCESS CONTROL: WHITELISTED CLIENT FROM "
+ + client
+ + " gets no search restrictions");
+ } else if ( !authenticated && !localhostAccess ) {
// in case that we do a global search or we want to fetch snippets, we check for DoS cases
- synchronized (trackerHandles) {
- final int accInThreeSeconds = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 3000)).size();
- final int accInOneMinute = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 60000)).size();
- final int accInTenMinutes = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 600000)).size();
+ synchronized ( trackerHandles ) {
+ final int accInThreeSeconds =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 3000)).size();
+ final int accInOneMinute =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 60000)).size();
+ final int accInTenMinutes =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 600000)).size();
// protections against too strong YaCy network load, reduces remote search
- if (global) {
- if (accInTenMinutes >= 60 || accInOneMinute >= 6 || accInThreeSeconds >= 1) {
+ if ( global ) {
+ if ( accInTenMinutes >= 60 || accInOneMinute >= 6 || accInThreeSeconds >= 1 ) {
global = false;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed global search");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed global search");
}
}
// protection against too many remote server snippet loads (protects traffic on server)
- if (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline()) {
- if (accInTenMinutes >= 20 || accInOneMinute >= 4 || accInThreeSeconds >= 1) {
+ if ( snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ) {
+ if ( accInTenMinutes >= 20 || accInOneMinute >= 4 || accInThreeSeconds >= 1 ) {
snippetFetchStrategy = CacheStrategy.CACHEONLY;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed remote snippet loading");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed remote snippet loading");
}
}
// general load protection
- if (accInTenMinutes >= 3000 || accInOneMinute >= 600 || accInThreeSeconds >= 60) {
+ if ( accInTenMinutes >= 3000 || accInOneMinute >= 600 || accInThreeSeconds >= 60 ) {
block = true;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed search");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed search");
}
}
}
- if (!block && (post == null || post.get("cat", "href").equals("href"))) {
+ if ( !block && (post == null || post.get("cat", "href").equals("href")) ) {
String urlmask = null;
// check available memory and clean up if necessary
- if (!MemoryControl.request(8000000L, false)) {
+ if ( !MemoryControl.request(8000000L, false) ) {
indexSegment.urlMetadata().clearCache();
SearchEventCache.cleanupEvents(true);
}
@@ -289,83 +356,85 @@ public class yacysearch { final RankingProfile ranking = sb.getRanking();
final StringBuilder modifier = new StringBuilder(20);
- if (querystring.indexOf("/near",0) >= 0) {
- querystring = querystring.replace("/near", "");
- ranking.coeff_worddistance = RankingProfile.COEFF_MAX;
- modifier.append("/near ");
+ if ( querystring.indexOf("/near", 0) >= 0 ) {
+ querystring = querystring.replace("/near", "");
+ ranking.coeff_worddistance = RankingProfile.COEFF_MAX;
+ modifier.append("/near ");
}
- if (querystring.indexOf("/date",0) >= 0) {
+ if ( querystring.indexOf("/date", 0) >= 0 ) {
querystring = querystring.replace("/date", "");
ranking.coeff_date = RankingProfile.COEFF_MAX;
modifier.append("/date ");
}
- if (querystring.indexOf("/http",0) >= 0) {
+ if ( querystring.indexOf("/http", 0) >= 0 ) {
querystring = querystring.replace("/http", "");
urlmask = "https?://.*";
modifier.append("/http ");
}
- if (querystring.indexOf("/https",0) >= 0) {
+ if ( querystring.indexOf("/https", 0) >= 0 ) {
querystring = querystring.replace("/https", "");
urlmask = "https?://.*";
modifier.append("/https ");
}
- if (querystring.indexOf("/ftp",0) >= 0) {
+ if ( querystring.indexOf("/ftp", 0) >= 0 ) {
querystring = querystring.replace("/ftp", "");
urlmask = "ftp://.*";
modifier.append("/ftp ");
}
- if (querystring.indexOf("/smb",0) >= 0) {
+ if ( querystring.indexOf("/smb", 0) >= 0 ) {
querystring = querystring.replace("/smb", "");
urlmask = "smb://.*";
modifier.append("/smb ");
}
- if (querystring.indexOf("/file",0) >= 0) {
+ if ( querystring.indexOf("/file", 0) >= 0 ) {
querystring = querystring.replace("/file", "");
urlmask = "file://.*";
modifier.append("/file ");
}
- if (querystring.indexOf("/location",0) >= 0) {
+ if ( querystring.indexOf("/location", 0) >= 0 ) {
querystring = querystring.replace("/location", "");
- if (constraint == null) {
+ if ( constraint == null ) {
constraint = new Bitfield(4);
}
constraint.set(Condenser.flag_cat_haslocation, true);
modifier.append("/location ");
}
- final int lrp = querystring.indexOf("/language/",0);
+ final int lrp = querystring.indexOf("/language/", 0);
String language = "";
- if (lrp >= 0) {
- if (querystring.length() >= (lrp + 12)) {
+ if ( lrp >= 0 ) {
+ if ( querystring.length() >= (lrp + 12) ) {
language = querystring.substring(lrp + 10, lrp + 12);
}
querystring = querystring.replace("/language/" + language, "");
language = language.toLowerCase();
modifier.append("/language/").append(language).append(" ");
}
- final int inurl = querystring.indexOf("inurl:",0);
- if (inurl >= 0) {
+ final int inurl = querystring.indexOf("inurl:", 0);
+ if ( inurl >= 0 ) {
int ftb = querystring.indexOf(' ', inurl);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
final String urlstr = querystring.substring(inurl + 6, ftb);
querystring = querystring.replace("inurl:" + urlstr, "");
- if (!urlstr.isEmpty()) {
+ if ( !urlstr.isEmpty() ) {
urlmask = urlmask == null ? ".*" + urlstr + ".*" : urlmask + urlstr + ".*";
}
modifier.append("inurl:").append(urlstr).append(" ");
}
- final int filetype = querystring.indexOf("filetype:",0);
- if (filetype >= 0) {
+ final int filetype = querystring.indexOf("filetype:", 0);
+ if ( filetype >= 0 ) {
int ftb = querystring.indexOf(' ', filetype);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
String ft = querystring.substring(filetype + 9, ftb);
querystring = querystring.replace("filetype:" + ft, "");
- while (!ft.isEmpty() && ft.charAt(0) == '.') ft = ft.substring(1);
- if (!ft.isEmpty()) {
- if (urlmask == null) {
+ while ( !ft.isEmpty() && ft.charAt(0) == '.' ) {
+ ft = ft.substring(1);
+ }
+ if ( !ft.isEmpty() ) {
+ if ( urlmask == null ) {
urlmask = ".*\\." + ft;
} else {
urlmask = urlmask + ".*\\." + ft;
@@ -374,133 +443,136 @@ public class yacysearch { modifier.append("filetype:").append(ft).append(" ");
}
String tenant = null;
- if (post.containsKey("tenant")) {
+ if ( post.containsKey("tenant") ) {
tenant = post.get("tenant");
- if (tenant != null && tenant.isEmpty()) {
+ if ( tenant != null && tenant.isEmpty() ) {
tenant = null;
}
- if (tenant != null) {
- if (urlmask == null) {
+ if ( tenant != null ) {
+ if ( urlmask == null ) {
urlmask = ".*" + tenant + ".*";
- } else urlmask = ".*" + tenant + urlmask;
+ } else {
+ urlmask = ".*" + tenant + urlmask;
+ }
}
}
- final int site = querystring.indexOf("site:",0);
+ final int site = querystring.indexOf("site:", 0);
String sitehash = null;
String sitehost = null;
- if (site >= 0) {
+ if ( site >= 0 ) {
int ftb = querystring.indexOf(' ', site);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
sitehost = querystring.substring(site + 5, ftb);
querystring = querystring.replace("site:" + sitehost, "");
- while (sitehost.length() > 0 && sitehost.charAt(0) == '.') {
+ while ( sitehost.length() > 0 && sitehost.charAt(0) == '.' ) {
sitehost = sitehost.substring(1);
}
- while (sitehost.endsWith(".")) {
+ while ( sitehost.endsWith(".") ) {
sitehost = sitehost.substring(0, sitehost.length() - 1);
}
sitehash = DigestURI.hosthash(sitehost);
modifier.append("site:").append(sitehost).append(" ");
}
- final int heuristicScroogle = querystring.indexOf("/heuristic/scroogle",0);
- if (heuristicScroogle >= 0) {
+ final int heuristicScroogle = querystring.indexOf("/heuristic/scroogle", 0);
+ if ( heuristicScroogle >= 0 ) {
querystring = querystring.replace("/heuristic/scroogle", "");
modifier.append("/heuristic/scroogle ");
}
- final int heuristicBlekko = querystring.indexOf("/heuristic/blekko",0);
- if (heuristicBlekko >= 0) {
+ final int heuristicBlekko = querystring.indexOf("/heuristic/blekko", 0);
+ if ( heuristicBlekko >= 0 ) {
querystring = querystring.replace("/heuristic/blekko", "");
modifier.append("/heuristic/blekko ");
}
- final int authori = querystring.indexOf("author:",0);
- String authorhash = null;
- if (authori >= 0) {
- // check if the author was given with single quotes or without
- final boolean quotes = (querystring.charAt(authori + 7) == (char) 39);
- String author;
- if (quotes) {
+ final int authori = querystring.indexOf("author:", 0);
+ String authorhash = null;
+ if ( authori >= 0 ) {
+ // check if the author was given with single quotes or without
+ final boolean quotes = (querystring.charAt(authori + 7) == (char) 39);
+ String author;
+ if ( quotes ) {
int ftb = querystring.indexOf((char) 39, authori + 8);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length() + 1;
}
author = querystring.substring(authori + 8, ftb);
querystring = querystring.replace("author:'" + author + "'", "");
modifier.append("author:'").append(author).append("' ");
- } else {
+ } else {
int ftb = querystring.indexOf(' ', authori);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
author = querystring.substring(authori + 7, ftb);
querystring = querystring.replace("author:" + author, "");
modifier.append("author:").append(author).append(" ");
- }
- authorhash = ASCII.String(Word.word2hash(author));
+ }
+ authorhash = ASCII.String(Word.word2hash(author));
}
- final int tld = querystring.indexOf("tld:",0);
- if (tld >= 0) {
+ final int tld = querystring.indexOf("tld:", 0);
+ if ( tld >= 0 ) {
int ftb = querystring.indexOf(' ', tld);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
String domain = querystring.substring(tld + 4, ftb);
querystring = querystring.replace("tld:" + domain, "");
modifier.append("tld:").append(domain).append(" ");
- while (domain.length() > 0 && domain.charAt(0) == '.') {
+ while ( domain.length() > 0 && domain.charAt(0) == '.' ) {
domain = domain.substring(1);
}
- if (domain.indexOf('.',0) < 0) {
+ if ( domain.indexOf('.', 0) < 0 ) {
domain = "\\." + domain;
} // is tld
- if (domain.length() > 0) {
+ if ( domain.length() > 0 ) {
urlmask = "[a-zA-Z]*://[^/]*" + domain + "/.*" + ((urlmask != null) ? urlmask : "");
}
}
- if (urlmask == null || urlmask.isEmpty()) {
+ if ( urlmask == null || urlmask.isEmpty() ) {
urlmask = originalUrlMask;
} //if no urlmask was given
// read the language from the language-restrict option 'lr'
// if no one is given, use the user agent or the system language as default
language = (post == null) ? language : post.get("lr", language);
- if (language.startsWith("lang_")) {
+ if ( language.startsWith("lang_") ) {
language = language.substring(5);
}
- if (!ISO639.exists(language)) {
+ if ( !ISO639.exists(language) ) {
// find out language of the user by reading of the user-agent string
String agent = header.get(HeaderFramework.ACCEPT_LANGUAGE);
- if (agent == null) {
+ if ( agent == null ) {
agent = System.getProperty("user.language");
}
language = (agent == null) ? "en" : ISO639.userAgentLanguageDetection(agent);
- if (language == null) {
+ if ( language == null ) {
language = "en";
}
}
// navigation
- final String navigation = (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "");
+ final String navigation =
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "");
// the query
final TreeSet<String>[] query = QueryParams.cleanQuery(querystring.trim()); // converts also umlaute
- final int maxDistance = (querystring.indexOf('"',0) >= 0) ? query.length - 1 : Integer.MAX_VALUE;
+ final int maxDistance = (querystring.indexOf('"', 0) >= 0) ? query.length - 1 : Integer.MAX_VALUE;
// filter out stopwords
final SortedSet<String> filtered = SetTools.joinConstructive(query[0], Switchboard.stopwords);
- if (!filtered.isEmpty()) {
+ if ( !filtered.isEmpty() ) {
SetTools.excludeDestructive(query[0], Switchboard.stopwords);
}
// if a minus-button was hit, remove a special reference first
- if (post != null && post.containsKey("deleteref")) {
+ if ( post != null && post.containsKey("deleteref") ) {
try {
- if (!sb.verifyAuthentication(header)) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
@@ -510,37 +582,45 @@ public class yacysearch { indexSegment.termIndex().remove(Word.words2hashesHandles(query[0]), delHash.getBytes());
// make new news message with negative voting
- if (!sb.isRobinsonMode()) {
+ if ( !sb.isRobinsonMode() ) {
final Map<String, String> map = new HashMap<String, String>();
map.put("urlhash", delHash);
map.put("vote", "negative");
map.put("refid", "");
- sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map);
+ sb.peers.newsPool.publishMyNews(
+ sb.peers.mySeed(),
+ NewsPool.CATEGORY_SURFTIPP_VOTE_ADD,
+ map);
}
// delete the search history since this still shows the entry
SearchEventCache.delete(delHash);
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
}
// if a plus-button was hit, create new voting message
- if (post != null && post.containsKey("recommendref")) {
- if (!sb.verifyAuthentication(header)) {
+ if ( post != null && post.containsKey("recommendref") ) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
final String recommendHash = post.get("recommendref", ""); // urlhash
final URIMetadataRow urlentry = indexSegment.urlMetadata().load(UTF8.getBytes(recommendHash));
- if (urlentry != null) {
+ if ( urlentry != null ) {
Document[] documents = null;
try {
- documents = sb.loader.loadDocuments(sb.loader.request(urlentry.url(), true, false), CacheStrategy.IFEXIST, 5000, Integer.MAX_VALUE);
- } catch (final IOException e) {
- } catch (final Parser.Failure e) {
+ documents =
+ sb.loader.loadDocuments(
+ sb.loader.request(urlentry.url(), true, false),
+ CacheStrategy.IFEXIST,
+ 5000,
+ Integer.MAX_VALUE);
+ } catch ( final IOException e ) {
+ } catch ( final Parser.Failure e ) {
}
- if (documents != null) {
+ if ( documents != null ) {
// create a news message
final Map<String, String> map = new HashMap<String, String>();
map.put("url", urlentry.url().toNormalform(false, true).replace(',', '|'));
@@ -548,24 +628,33 @@ public class yacysearch { map.put("description", documents[0].dc_title().replace(',', ' '));
map.put("author", documents[0].dc_creator());
map.put("tags", documents[0].dc_subject(' '));
- sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_SURFTIPP_ADD, map);
+ sb.peers.newsPool.publishMyNews(
+ sb.peers.mySeed(),
+ NewsPool.CATEGORY_SURFTIPP_ADD,
+ map);
documents[0].close();
}
}
}
// if a bookmarks-button was hit, create new bookmark entry
- if (post != null && post.containsKey("bookmarkref")) {
- if (!sb.verifyAuthentication(header)) {
+ if ( post != null && post.containsKey("bookmarkref") ) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
final String bookmarkHash = post.get("bookmarkref", ""); // urlhash
final URIMetadataRow urlentry = indexSegment.urlMetadata().load(UTF8.getBytes(bookmarkHash));
- if (urlentry != null) {
+ if ( urlentry != null ) {
try {
- sb.tables.bookmarks.createBookmark(sb.loader, urlentry.url(), YMarkTables.USER_ADMIN, true, "searchresult", "/search");
- } catch (final Throwable e) {
+ sb.tables.bookmarks.createBookmark(
+ sb.loader,
+ urlentry.url(),
+ YMarkTables.USER_ADMIN,
+ true,
+ "searchresult",
+ "/search");
+ } catch ( final Throwable e ) {
}
}
}
@@ -577,7 +666,7 @@ public class yacysearch { // check filters
try {
Pattern.compile(urlmask);
- } catch (final PatternSyntaxException ex) {
+ } catch ( final PatternSyntaxException ex ) {
Log.logWarning("SEARCH", "Illegal URL mask, not a valid regex: " + urlmask);
prop.put("urlmaskerror", 1);
prop.putHTML("urlmaskerror_urlmask", urlmask);
@@ -586,14 +675,15 @@ public class yacysearch { try {
Pattern.compile(prefermask);
- } catch (final PatternSyntaxException ex) {
+ } catch ( final PatternSyntaxException ex ) {
Log.logWarning("SEARCH", "Illegal prefer mask, not a valid regex: " + prefermask);
prop.put("prefermaskerror", 1);
prop.putHTML("prefermaskerror_prefermask", prefermask);
prefermask = "";
}
- final QueryParams theQuery = new QueryParams(
+ final QueryParams theQuery =
+ new QueryParams(
originalquerystring,
queryHashes,
Word.words2hashesHandles(query[1]),
@@ -610,8 +700,9 @@ public class yacysearch { maximumRecords,
startRecord,
urlmask,
- clustersearch && global ? QueryParams.Searchdom.CLUSTER :
- (global && indexReceiveGranted ? QueryParams.Searchdom.GLOBAL : QueryParams.Searchdom.LOCAL),
+ clustersearch && global ? QueryParams.Searchdom.CLUSTER : (global && indexReceiveGranted
+ ? QueryParams.Searchdom.GLOBAL
+ : QueryParams.Searchdom.LOCAL),
20,
constraint,
true,
@@ -624,9 +715,16 @@ public class yacysearch { indexSegment,
ranking,
header.get(RequestHeader.USER_AGENT, ""),
- sb.getConfigBool(SwitchboardConstants.SEARCH_VERIFY_DELETE, false) && sb.getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false) && sb.peers.mySeed().getFlagAcceptRemoteIndex());
+ sb.getConfigBool(SwitchboardConstants.SEARCH_VERIFY_DELETE, false)
+ && sb.getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false)
+ && sb.peers.mySeed().getFlagAcceptRemoteIndex());
EventTracker.delete(EventTracker.EClass.SEARCH);
- EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(theQuery.id(true), SearchEvent.Type.INITIALIZATION, "", 0, 0), false);
+ EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(
+ theQuery.id(true),
+ SearchEvent.Type.INITIALIZATION,
+ "",
+ 0,
+ 0), false);
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
@@ -635,44 +733,81 @@ public class yacysearch { theQuery.filterOut(Switchboard.blueList);
// log
- Log.logInfo("LOCAL_SEARCH", "INIT WORD SEARCH: " + theQuery.queryString + ":" + QueryParams.hashSet2hashString(theQuery.queryHashes) + " - " + theQuery.neededResults() + " links to be computed, " + theQuery.displayResults() + " lines to be displayed");
- EventChannel.channels(EventChannel.LOCALSEARCH).addMessage(new RSSMessage("Local Search Request", theQuery.queryString, ""));
+ Log.logInfo(
+ "LOCAL_SEARCH",
+ "INIT WORD SEARCH: "
+ + theQuery.queryString
+ + ":"
+ + QueryParams.hashSet2hashString(theQuery.queryHashes)
+ + " - "
+ + theQuery.neededResults()
+ + " links to be computed, "
+ + theQuery.displayResults()
+ + " lines to be displayed");
+ EventChannel.channels(EventChannel.LOCALSEARCH).addMessage(
+ new RSSMessage("Local Search Request", theQuery.queryString, ""));
final long timestamp = System.currentTimeMillis();
// create a new search event
- if (SearchEventCache.getEvent(theQuery.id(false)) == null) {
+ if ( SearchEventCache.getEvent(theQuery.id(false)) == null ) {
theQuery.setOffset(0); // in case that this is a new search, always start without a offset
startRecord = 0;
}
- final SearchEvent theSearch = SearchEventCache.getEvent(
- theQuery, sb.peers, sb.tables, (sb.isRobinsonMode()) ? sb.clusterhashes : null, false, sb.loader,
- (int) sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_USER, sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_DEFAULT, 10)),
- sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_USER, sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000)),
- (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_ROBINSON, 0),
- (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_MULTIWORD, 0));
-
- if (startRecord == 0) {
- if (sitehost != null && sb.getConfigBool("heuristic.site", false) && authenticated) {
+ final SearchEvent theSearch =
+ SearchEventCache.getEvent(
+ theQuery,
+ sb.peers,
+ sb.tables,
+ (sb.isRobinsonMode()) ? sb.clusterhashes : null,
+ false,
+ sb.loader,
+ (int) sb.getConfigLong(
+ SwitchboardConstants.REMOTESEARCH_MAXCOUNT_USER,
+ sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_DEFAULT, 10)),
+ sb.getConfigLong(
+ SwitchboardConstants.REMOTESEARCH_MAXTIME_USER,
+ sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000)),
+ (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_ROBINSON, 0),
+ (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_MULTIWORD, 0));
+
+ if ( startRecord == 0 ) {
+ if ( sitehost != null && sb.getConfigBool("heuristic.site", false) && authenticated ) {
sb.heuristicSite(theSearch, sitehost);
}
- if ((heuristicScroogle >= 0 || sb.getConfigBool("heuristic.scroogle", false)) && authenticated) {
+ if ( (heuristicScroogle >= 0 || sb.getConfigBool("heuristic.scroogle", false))
+ && authenticated ) {
sb.heuristicScroogle(theSearch);
}
- if ((heuristicBlekko >= 0 || sb.getConfigBool("heuristic.blekko", false)) && authenticated) {
+ if ( (heuristicBlekko >= 0 || sb.getConfigBool("heuristic.blekko", false)) && authenticated ) {
sb.heuristicRSS("http://blekko.com/ws/$+/rss", theSearch, "blekko");
}
}
// log
- Log.logInfo("LOCAL_SEARCH", "EXIT WORD SEARCH: " + theQuery.queryString + " - " +
- "local-unfiltered(" + theSearch.getRankingResult().getLocalIndexCount() + "), " +
- "local_miss(" + theSearch.getRankingResult().getMissCount() + "), " +
- "local_sortout(" + theSearch.getRankingResult().getSortOutCount() + "), " +
- "remote(" + theSearch.getRankingResult().getRemoteResourceSize() + ") links found, " +
- (System.currentTimeMillis() - timestamp) + " ms");
+ Log.logInfo("LOCAL_SEARCH", "EXIT WORD SEARCH: "
+ + theQuery.queryString
+ + " - "
+ + "local-unfiltered("
+ + theSearch.getRankingResult().getLocalIndexCount()
+ + "), "
+ + "local_miss("
+ + theSearch.getRankingResult().getMissCount()
+ + "), "
+ + "local_sortout("
+ + theSearch.getRankingResult().getSortOutCount()
+ + "), "
+ + "remote("
+ + theSearch.getRankingResult().getRemoteResourceSize()
+ + ") links found, "
+ + (System.currentTimeMillis() - timestamp)
+ + " ms");
// prepare search statistics
- theQuery.resultcount = theSearch.getRankingResult().getLocalIndexCount() - theSearch.getRankingResult().getMissCount() - theSearch.getRankingResult().getSortOutCount() + theSearch.getRankingResult().getRemoteIndexCount();
+ theQuery.resultcount =
+ theSearch.getRankingResult().getLocalIndexCount()
+ - theSearch.getRankingResult().getMissCount()
+ - theSearch.getRankingResult().getSortOutCount()
+ + theSearch.getRankingResult().getRemoteIndexCount();
theQuery.searchtime = System.currentTimeMillis() - timestamp;
theQuery.urlretrievaltime = theSearch.result().getURLRetrievalTime();
theQuery.snippetcomputationtime = theSearch.result().getSnippetComputationTime();
@@ -682,22 +817,29 @@ public class yacysearch { final int meanMax = (post != null) ? post.getInt("meanCount", 0) : 0;
prop.put("meanCount", meanMax);
- if (meanMax > 0 && !json && !rss) {
- final DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), new StringBuilder(querystring));
- final Iterator<StringBuilder> meanIt = didYouMean.getSuggestions(100, 5).iterator();
+ if ( meanMax > 0 && !json && !rss ) {
+ final DidYouMean didYouMean =
+ new DidYouMean(indexSegment.termIndex(), new StringBuilder(querystring));
+ final Iterator<StringBuilder> meanIt = didYouMean.getSuggestions(100, 5).iterator();
int meanCount = 0;
String suggestion;
- while( meanCount<meanMax && meanIt.hasNext()) {
+ while ( meanCount < meanMax && meanIt.hasNext() ) {
suggestion = meanIt.next().toString();
- prop.put("didYouMean_suggestions_"+meanCount+"_word", suggestion);
- prop.put("didYouMean_suggestions_"+meanCount+"_url",
- QueryParams.navurl("html", 0, theQuery, suggestion, originalUrlMask.toString(), theQuery.navigators).toString()
- );
- prop.put("didYouMean_suggestions_"+meanCount+"_sep","|");
+ prop.put("didYouMean_suggestions_" + meanCount + "_word", suggestion);
+ prop.put(
+ "didYouMean_suggestions_" + meanCount + "_url",
+ QueryParams.navurl(
+ "html",
+ 0,
+ theQuery,
+ suggestion,
+ originalUrlMask.toString(),
+ theQuery.navigators).toString());
+ prop.put("didYouMean_suggestions_" + meanCount + "_sep", "|");
meanCount++;
}
- prop.put("didYouMean_suggestions_"+(meanCount-1)+"_sep","");
- prop.put("didYouMean", meanCount>0 ? 1:0);
+ prop.put("didYouMean_suggestions_" + (meanCount - 1) + "_sep", "");
+ prop.put("didYouMean", meanCount > 0 ? 1 : 0);
prop.put("didYouMean_suggestions", meanCount);
} else {
prop.put("didYouMean", 0);
@@ -705,16 +847,18 @@ public class yacysearch { // find geographic info
final SortedSet<Location> coordinates = LibraryProvider.geoLoc.find(originalquerystring, false);
- if (coordinates == null || coordinates.isEmpty() || startRecord > 0) {
+ if ( coordinates == null || coordinates.isEmpty() || startRecord > 0 ) {
prop.put("geoinfo", "0");
} else {
int i = 0;
- for (final Location c: coordinates) {
+ for ( final Location c : coordinates ) {
prop.put("geoinfo_loc_" + i + "_lon", Math.round(c.lon() * 10000.0f) / 10000.0f);
prop.put("geoinfo_loc_" + i + "_lat", Math.round(c.lat() * 10000.0f) / 10000.0f);
prop.put("geoinfo_loc_" + i + "_name", c.getName());
i++;
- if (i >= 10) break;
+ if ( i >= 10 ) {
+ break;
+ }
}
prop.put("geoinfo_loc", i);
prop.put("geoinfo", "1");
@@ -722,47 +866,79 @@ public class yacysearch { // update the search tracker
try {
- synchronized (trackerHandles) {
+ synchronized ( trackerHandles ) {
trackerHandles.add(theQuery.time);
- while (trackerHandles.size() > 600) {
- if (!trackerHandles.remove(trackerHandles.first())) break;
+ while ( trackerHandles.size() > 600 ) {
+ if ( !trackerHandles.remove(trackerHandles.first()) ) {
+ break;
+ }
}
}
sb.localSearchTracker.put(client, trackerHandles);
- if (sb.localSearchTracker.size() > 100) {
+ if ( sb.localSearchTracker.size() > 100 ) {
sb.localSearchTracker.remove(sb.localSearchTracker.keys().nextElement());
}
- if (MemoryControl.shortStatus()) sb.localSearchTracker.clear();
- } catch (final Exception e) {
+ if ( MemoryControl.shortStatus() ) {
+ sb.localSearchTracker.clear();
+ }
+ } catch ( final Exception e ) {
Log.logException(e);
}
- final int indexcount = theSearch.getRankingResult().getLocalIndexCount() - theSearch.getRankingResult().getMissCount() - theSearch.getRankingResult().getSortOutCount() + theSearch.getRankingResult().getRemoteIndexCount();
+ final int indexcount =
+ theSearch.getRankingResult().getLocalIndexCount()
+ - theSearch.getRankingResult().getMissCount()
+ - theSearch.getRankingResult().getSortOutCount()
+ + theSearch.getRankingResult().getRemoteIndexCount();
prop.put("num-results_offset", startRecord == 0 ? 0 : startRecord + 1);
- prop.put("num-results_itemscount", Formatter.number(startRecord + theSearch.getQuery().itemsPerPage > indexcount ? startRecord + indexcount % theSearch.getQuery().itemsPerPage : startRecord + theSearch.getQuery().itemsPerPage, true));
+ prop.put("num-results_itemscount", Formatter.number(
+ startRecord + theSearch.getQuery().itemsPerPage > indexcount ? startRecord
+ + indexcount
+ % theSearch.getQuery().itemsPerPage : startRecord + theSearch.getQuery().itemsPerPage,
+ true));
prop.put("num-results_itemsPerPage", maximumRecords);
prop.put("num-results_totalcount", Formatter.number(indexcount, true));
- 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));
- prop.put("num-results_globalresults_remoteIndexCount", Formatter.number(theSearch.getRankingResult().getRemoteIndexCount(), true));
- prop.put("num-results_globalresults_remotePeerCount", Formatter.number(theSearch.getRankingResult().getRemotePeerCount(), true));
+ 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));
+ prop.put(
+ "num-results_globalresults_remoteIndexCount",
+ Formatter.number(theSearch.getRankingResult().getRemoteIndexCount(), true));
+ prop.put(
+ "num-results_globalresults_remotePeerCount",
+ Formatter.number(theSearch.getRankingResult().getRemotePeerCount(), true));
// compose page navigation
final StringBuilder resnav = new StringBuilder(200);
final int thispage = startRecord / theQuery.displayResults();
- if (thispage == 0) {
- resnav.append("<img src=\"env/grafics/navdl.gif\" alt=\"arrowleft\" width=\"16\" height=\"16\" /> ");
+ if ( thispage == 0 ) {
+ resnav
+ .append("<img src=\"env/grafics/navdl.gif\" alt=\"arrowleft\" width=\"16\" height=\"16\" /> ");
} else {
- resnav.append("<a id=\"prevpage\" href=\"");
- resnav.append(QueryParams.navurl("html", thispage - 1, theQuery, null, originalUrlMask, navigation).toString());
- resnav.append("\"><img src=\"env/grafics/navdl.gif\" alt=\"arrowleft\" width=\"16\" height=\"16\" /></a> ");
+ resnav.append("<a id=\"prevpage\" href=\"");
+ resnav.append(QueryParams.navurl(
+ "html",
+ thispage - 1,
+ theQuery,
+ null,
+ originalUrlMask,
+ navigation).toString());
+ resnav
+ .append("\"><img src=\"env/grafics/navdl.gif\" alt=\"arrowleft\" width=\"16\" height=\"16\" /></a> ");
}
final int numberofpages = Math.min(10, 1 + ((indexcount - 1) / theQuery.displayResults()));
- for (int i = 0; i < numberofpages; i++) {
- if (i == thispage) {
+ for ( int i = 0; i < numberofpages; i++ ) {
+ if ( i == thispage ) {
resnav.append("<img src=\"env/grafics/navs");
resnav.append(i + 1);
resnav.append(".gif\" alt=\"page");
@@ -770,7 +946,9 @@ public class yacysearch { resnav.append("\" width=\"16\" height=\"16\" /> ");
} else {
resnav.append("<a href=\"");
- resnav.append(QueryParams.navurl("html", i, theQuery, null, originalUrlMask, navigation).toString());
+ resnav.append(QueryParams
+ .navurl("html", i, theQuery, null, originalUrlMask, navigation)
+ .toString());
resnav.append("\"><img src=\"env/grafics/navd");
resnav.append(i + 1);
resnav.append(".gif\" alt=\"page");
@@ -778,12 +956,20 @@ public class yacysearch { resnav.append("\" width=\"16\" height=\"16\" /></a> ");
}
}
- if (thispage >= numberofpages) {
- resnav.append("<img src=\"env/grafics/navdr.gif\" alt=\"arrowright\" width=\"16\" height=\"16\" />");
+ if ( thispage >= numberofpages ) {
+ resnav
+ .append("<img src=\"env/grafics/navdr.gif\" alt=\"arrowright\" width=\"16\" height=\"16\" />");
} else {
resnav.append("<a id=\"nextpage\" href=\"");
- resnav.append(QueryParams.navurl("html", thispage + 1, theQuery, null, originalUrlMask, navigation).toString());
- resnav.append("\"><img src=\"env/grafics/navdr.gif\" alt=\"arrowright\" width=\"16\" height=\"16\" /></a>");
+ resnav.append(QueryParams.navurl(
+ "html",
+ thispage + 1,
+ theQuery,
+ null,
+ originalUrlMask,
+ navigation).toString());
+ resnav
+ .append("\"><img src=\"env/grafics/navdr.gif\" alt=\"arrowright\" width=\"16\" height=\"16\" /></a>");
}
final String resnavs = resnav.toString();
prop.put("num-results_resnav", resnavs);
@@ -791,24 +977,29 @@ public class yacysearch { prop.put("pageNavBottom_resnav", resnavs);
// generate the search result lines; the content will be produced by another servlet
- for (int i = 0; i < theQuery.displayResults(); i++) {
+ for ( int i = 0; i < theQuery.displayResults(); i++ ) {
prop.put("results_" + i + "_item", startRecord + i);
prop.put("results_" + i + "_eventID", theQuery.id(false));
}
prop.put("results", theQuery.displayResults());
- prop.put("resultTable", (contentdom == ContentDomain.APP || contentdom == ContentDomain.AUDIO || contentdom == ContentDomain.VIDEO) ? 1 : 0);
+ prop
+ .put(
+ "resultTable",
+ (contentdom == ContentDomain.APP || contentdom == ContentDomain.AUDIO || contentdom == ContentDomain.VIDEO)
+ ? 1
+ : 0);
prop.put("eventID", theQuery.id(false)); // for bottomline
// process result of search
- if (!filtered.isEmpty()) {
+ if ( !filtered.isEmpty() ) {
prop.put("excluded", "1");
prop.putHTML("excluded_stopwords", filtered.toString());
} else {
prop.put("excluded", "0");
}
- if (prop == null || prop.isEmpty()) {
- if (post.get("query", post.get("search", "")).length() < 2) {
+ if ( prop == null || prop.isEmpty() ) {
+ if ( post.get("query", post.get("search", "")).length() < 2 ) {
prop.put("num-results", "2"); // no results - at least 2 chars
} else {
prop.put("num-results", "1"); // no results
@@ -822,7 +1013,7 @@ public class yacysearch { // adding some additional properties needed for the rss feed
String hostName = header.get("Host", "localhost");
- if (hostName.indexOf(':',0) == -1) {
+ if ( hostName.indexOf(':', 0) == -1 ) {
hostName += ":" + serverCore.getPortNr(env.getConfig("port", "8090"));
}
prop.put("searchBaseURL", "http://" + hostName + "/yacysearch.html");
@@ -838,10 +1029,20 @@ public class yacysearch { prop.putHTML("prefermaskfilter", prefermask);
prop.put("indexof", (indexof) ? "on" : "off");
prop.put("constraint", (constraint == null) ? "" : constraint.exportB64());
- prop.put("search.verify", snippetFetchStrategy == null ? sb.getConfig("search.verify", "iffresh") : snippetFetchStrategy.toName());
- prop.put("search.navigation", (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
+ prop.put("search.verify", snippetFetchStrategy == null
+ ? sb.getConfig("search.verify", "iffresh")
+ : snippetFetchStrategy.toName());
+ prop.put(
+ "search.navigation",
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
prop.put("contentdom", (post == null ? "text" : post.get("contentdom", "text")));
- prop.put("searchdomswitches", sb.getConfigBool("search.text", true) || sb.getConfigBool("search.audio", true) || sb.getConfigBool("search.video", true) || sb.getConfigBool("search.image", true) || sb.getConfigBool("search.app", true) ? 1 : 0);
+ prop.put(
+ "searchdomswitches",
+ sb.getConfigBool("search.text", true)
+ || sb.getConfigBool("search.audio", true)
+ || sb.getConfigBool("search.video", true)
+ || sb.getConfigBool("search.image", true)
+ || sb.getConfigBool("search.app", true) ? 1 : 0);
prop.put("searchdomswitches_searchtext", sb.getConfigBool("search.text", true) ? 1 : 0);
prop.put("searchdomswitches_searchaudio", sb.getConfigBool("search.audio", true) ? 1 : 0);
prop.put("searchdomswitches_searchvideo", sb.getConfigBool("search.video", true) ? 1 : 0);
|
