mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) Searchword highlighting for info page
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1036 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
f9fb284fb7
commit
dd24f0252f
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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}#
|
||||
|
||||
|
|
|
@ -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", "");
|
||||
|
|
Loading…
Reference in New Issue
Block a user