Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) minor changes *) fixed potential NPE in suggest.java

low012bea81379971f
diff --git a/htroot/WebStructurePicture_p.java b/htroot/WebStructurePicture_p.java
index bedc6f5e9..89fe5dc4f 100644
--- a/htroot/WebStructurePicture_p.java
+++ b/htroot/WebStructurePicture_p.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import net.yacy.cora.document.UTF8;
@@ -95,7 +96,7 @@ public class WebStructurePicture_p {
// find domain with most references
host = sb.webStructure.hostWithMaxReferences();
}
- RasterPlotter graphPicture;
+ final RasterPlotter graphPicture;
if (host == null) {
// probably no information available
graphPicture = new RasterPlotter(width, height, RasterPlotter.DrawMode.MODE_SUB, color_back);
@@ -132,9 +133,9 @@ public class WebStructurePicture_p {
GraphPlotter.coordinate center = graph.getPoint(centerhost);
int mynodes = 0;
if (center == null) {
- /*center =*/ graph.addPoint(centerhost, x, y, nextlayer);
- maxnodes--;
- mynodes++;
+ graph.addPoint(centerhost, x, y, nextlayer);
+ maxnodes--;
+ mynodes++;
}
if (nextlayer == maxlayer) return mynodes;
nextlayer++;
@@ -145,7 +146,7 @@ public class WebStructurePicture_p {
String targethash, targethost;
// first set points to next hosts
final Iterator<Map.Entry<String, Integer>> i = next.entrySet().iterator();
- final ArrayList<String[]> targets = new ArrayList<String[]>();
+ final List<String[]> targets = new ArrayList<String[]>();
int maxtargetrefs = 8, maxthisrefs = 8;
int targetrefs, thisrefs;
double rr, re;
diff --git a/htroot/suggest.java b/htroot/suggest.java
index 9ed0c941c..37d62edbd 100644
--- a/htroot/suggest.java
+++ b/htroot/suggest.java
@@ -1,8 +1,12 @@
-// suggestionsjava
+// suggest.java
// -----------------------
// (C) 2010 by Michael Peter Christen; [email protected]
// first published 11.10.2010 in Frankfurt, Germany on http://yacy.net
//
+// $LastChangedDate$
+// $LastChangedRevision$
+// $LastChangedBy$
+//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
@@ -60,17 +64,20 @@ public class suggest {
final boolean more = post != null && post.containsKey("more");
// get query
- String originalquerystring = (post == null) ? "" : post.get("query", post.get("q", "")).trim();
- String querystring = originalquerystring.replace('+', ' ');
- int timeout = (post == null) ? 300 : post.getInt("timeout", 300);
- int count = (post == null) ? 20 : post.getInt("count", 20);
+ final String originalquerystring = (post == null) ? "" : post.get("query", post.get("q", "")).trim();
+ final String querystring = originalquerystring.replace('+', ' ');
+ final int timeout = (post == null) ? 300 : post.getInt("timeout", 300);
+ final int count = (post == null) ? 20 : post.getInt("count", 20);
// get segment
- Segment indexSegment = null;
+ final Segment indexSegment;
if (post != null && post.containsKey("segment")) {
String segmentName = post.get("segment");
if (sb.indexSegments.segmentExist(segmentName)) {
indexSegment = sb.indexSegments.segment(segmentName);
+ } else {
+ // take default segment
+ indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);
}
} else {
// take default segment
@@ -78,26 +85,39 @@ public class suggest {
}
int c = 0;
- if (more || !indexSegment.termIndex().has(Word.word2hash(querystring))) {
- DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), querystring);
- Iterator<String> meanIt = didYouMean.getSuggestions(timeout, count).iterator();
+ if (more ||
+ (indexSegment != null &&
+ !indexSegment.termIndex().has(Word.word2hash(querystring))))
+ {
+ final DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), querystring);
+ final Iterator<String> meanIt = didYouMean.getSuggestions(timeout, count).iterator();
String suggestion;
//[#[query]#,[#{suggestions}##[text]##(eol)#,::#(/eol)##{/suggestions}#]]
while (c < meanMax && meanIt.hasNext()) {
suggestion = meanIt.next();
- if (json) prop.putJSON("suggestions_" + c + "_text", suggestion);
- else if (xml) prop.putXML("suggestions_" + c + "_text", suggestion);
- else prop.putHTML("suggestions_" + c + "_text", suggestion);
+ if (json) {
+ prop.putJSON("suggestions_" + c + "_text", suggestion);
+ } else if (xml) {
+ prop.putXML("suggestions_" + c + "_text", suggestion);
+ } else {
+ prop.putHTML("suggestions_" + c + "_text", suggestion);
+ }
prop.put("suggestions_" + c + "_eol", 0);
c++;
}
}
- if (c > 0) prop.put("suggestions_" + (c - 1) + "_eol", 1);
+ if (c > 0) {
+ prop.put("suggestions_" + (c - 1) + "_eol", 1);
+ }
prop.put("suggestions", c);
- if (json) prop.putJSON("query", originalquerystring);
- else if (xml) prop.putXML("query", originalquerystring);
- else prop.putHTML("query", originalquerystring);
+ if (json) {
+ prop.putJSON("query", originalquerystring);
+ } else if (xml) {
+ prop.putXML("query", originalquerystring);
+ } else {
+ prop.putHTML("query", originalquerystring);
+ }
// Adding CORS Access header for xml output
if (xml) {
diff --git a/htroot/yacyinteractive.java b/htroot/yacyinteractive.java
index c38a07aeb..116d5f2e4 100644
--- a/htroot/yacyinteractive.java
+++ b/htroot/yacyinteractive.java
@@ -38,13 +38,15 @@ public class yacyinteractive {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
- String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, "");
- if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");
+ final String promoteSearchPageGreeting =
+ (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ?
+ env.getConfig("network.unit.description", "") :
+ env.getConfig(SwitchboardConstants.GREETING, "");
prop.put("promoteSearchPageGreeting", promoteSearchPageGreeting);
prop.put("promoteSearchPageGreeting.homepage", sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
prop.put("promoteSearchPageGreeting.smallImage", sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
- String query = (post == null) ? "" : post.get("query", "");
+ final String query = (post == null) ? "" : post.get("query", "");
prop.putHTML("query", query);
prop.putHTML("querys", query.replaceAll(" ", "+"));
return prop;
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 4987ceba9..712f5d06c 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -76,7 +77,6 @@ import de.anomic.server.servletProperties;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.graphics.ProfilingGraph;
import de.anomic.yacy.yacyChannel;
-import java.util.Map;
public class yacysearch {