Skip to content

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

*) Searchword highlighting for info page

thelidd24f0252f05
diff --git a/htroot/ViewFile.html b/htroot/ViewFile.html
index 07be4b480..50285269a 100644
--- a/htroot/ViewFile.html
+++ b/htroot/ViewFile.html
@@ -35,10 +35,10 @@
<tr class="TableCellDark">
<td>View as:</td>
<td>
- <a href="?urlHash=#[hash]#&viewMode=iframe">Original</a> |
- <a href="?urlHash=#[hash]#&viewMode=plain">Plain Text</a> |
- <a href="?urlHash=#[hash]#&viewMode=parsed">Parsed Text</a> |
- <a href="?urlHash=#[hash]#&viewMode=sentences">Parsed Sentences</a>
+ <a href="?urlHash=#[hash]#&viewMode=iframe&words=#[words]#">Original</a> |
+ <a href="?urlHash=#[hash]#&viewMode=plain&words=#[words]#">Plain Text</a> |
+ <a href="?urlHash=#[hash]#&viewMode=parsed&words=#[words]#">Parsed Text</a> |
+ <a href="?urlHash=#[hash]#&viewMode=sentences&words=#[words]#">Parsed Sentences</a>
</td>
</tr>
</table>
diff --git a/htroot/ViewFile.java b/htroot/ViewFile.java
index ce94aa971..aaa32d5c8 100644
--- a/htroot/ViewFile.java
+++ b/htroot/ViewFile.java
@@ -45,7 +45,10 @@
//if the shell's current path is HTROOT
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaParserDocument;
@@ -61,11 +64,27 @@ public class ViewFile {
public static final int VIEW_MODE_AS_PARSED_TEXT = 2;
public static final int VIEW_MODE_AS_PARSED_SENTENCES = 3;
public static final int VIEW_MODE_AS_IFRAME = 4;
+
+ public static final String[] highlightingColors = new String[] {
+ "255,255,100",
+ "255,155,155",
+ "0,255,0",
+ "0,255,255",
+ "204,153,0",
+ "204,153,255"
+ };
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
serverObjects prop = new serverObjects();
plasmaSwitchboard sb = (plasmaSwitchboard)env;
+ if (post.containsKey("words"))
+ try {
+ prop.put("error_words",URLEncoder.encode((String) post.get("words"), "UTF-8"));
+ } catch (UnsupportedEncodingException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
if (post != null) {
// getting the url hash from which the content should be loaded
@@ -76,7 +95,7 @@ public class ViewFile {
return prop;
}
- String viewMode = post.get("viewMode","plain");
+ String viewMode = post.get("viewMode","sentences");
// getting the urlEntry that belongs to the url hash
Entry urlEntry = sb.urlPool.loadedURL.getEntry(urlHash);
@@ -151,8 +170,26 @@ public class ViewFile {
boolean dark = true;
for (int i=0; i < sentences.length; i++) {
+ String currentSentence = sentences[i];
+
+ // Search word highlighting
+ String words = post.get("words",null);
+ if (words != null) {
+ try {
+ words = URLDecoder.decode(words,"UTF-8");
+ } catch (UnsupportedEncodingException e) {}
+
+ String[] wordArray = words.substring(1,words.length()-1).split(",");
+ for (int j=0; j < wordArray.length; j++) {
+ String currentWord = wordArray[j].trim();
+ currentSentence = currentSentence.replaceAll(currentWord,
+ "<b style=\"color: black; background-color: rgb(" + highlightingColors[j%6] + ");\">" + currentWord + "</b>");
+ }
+ }
+
+
prop.put("viewMode_sentences_" + i + "_nr",Integer.toString(i+1));
- prop.put("viewMode_sentences_" + i + "_text",sentences[i]);
+ prop.put("viewMode_sentences_" + i + "_text",currentSentence);
prop.put("viewMode_sentences_" + i + "_dark",((dark) ? 1 : 0) ); dark=!dark;
}
prop.put("viewMode_sentences",sentences.length);
diff --git a/htroot/index.html b/htroot/index.html
index 14b024440..e672eeefc 100644
--- a/htroot/index.html
+++ b/htroot/index.html
@@ -101,7 +101,7 @@ from 'late' peers.
<p><b>#[description]#</b><br>
#(snippet)#::<i>#[text]#</i><br>#(/snippet)#
<a href="#[url]#">#[urlname]#</a><br>
-#[date]# | <a href="ViewFile.html?urlHash=#[urlhash]#">Info</a><br></p>
+#[date]# | <a href="ViewFile.html?urlHash=#[urlhash]#&words=#[words]#">Info</a><br></p>
<!-- link end -->
#{/results}#
diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java
index 3ff64f403..656400a16 100644
--- a/source/de/anomic/plasma/plasmaSwitchboard.java
+++ b/source/de/anomic/plasma/plasmaSwitchboard.java
@@ -107,6 +107,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -1563,7 +1564,9 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
prop.put("results_" + i + "_urlhash", urlhash);
prop.put("results_" + i + "_urlname", urlname);
prop.put("results_" + i + "_date", dateString(urlentry.moddate()));
- prop.put("results_" + i + "_size", Long.toString(urlentry.size()));
+ prop.put("results_" + i + "_size", Long.toString(urlentry.size()));
+ prop.put("results_" + i + "_words",URLEncoder.encode(query.queryWords.toString(),"UTF-8"));
+ // adding snippet if available
if (snippet.line == null) {
prop.put("results_" + i + "_snippet", 0);
prop.put("results_" + i + "_snippet_text", "");