Snippets that are not available on page load time will be fetched using ajax requests. see: http://www.yacy-forum.de/viewtopic.php?p=16479 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1748 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
7e7a72b108
commit
dc9174c809
@ -0,0 +1,46 @@
|
||||
|
||||
function AllSnippets() {
|
||||
var query = document.getElementsByName("former")[0].value;
|
||||
|
||||
var span = document.getElementsByTagName("span");
|
||||
for(var x=0;x<span.length;x++) {
|
||||
if (span[x].className == 'snippetLoading') {
|
||||
var url = document.getElementById("url" + span[x].id);
|
||||
requestSnippet(url,query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function requestSnippet(url, query){
|
||||
var req=createRequestObject();
|
||||
req.open('get', '/xml/snippet.xml?url=' + escape(url) + '&search=' + escape(query),true);
|
||||
req.onreadystatechange = function () {handleState(req)};
|
||||
req.send(null);
|
||||
}
|
||||
|
||||
function handleState(req) {
|
||||
if(req.readyState != 4){
|
||||
return;
|
||||
}
|
||||
|
||||
var response = req.responseXML;
|
||||
|
||||
var snippetText = response.getElementsByTagName("text")[0].firstChild.data;
|
||||
var urlHash = response.getElementsByTagName("urlHash")[0].firstChild.data;
|
||||
var status = response.getElementsByTagName("status")[0].firstChild.data;
|
||||
|
||||
var span = document.getElementById(urlHash)
|
||||
span.removeChild(span.firstChild);
|
||||
|
||||
if (status < 11) {
|
||||
span.className = "snippetLoaded";
|
||||
//span.setAttribute("class", "snippetLoaded");
|
||||
} else {
|
||||
span.className = "snippetError";
|
||||
//span.setAttribute("class", "snippetError");
|
||||
}
|
||||
|
||||
var snippetNode = document.createTextNode(snippetText);
|
||||
span.appendChild(snippetNode);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package xml;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import de.anomic.http.httpHeader;
|
||||
import de.anomic.kelondro.kelondroMSetTools;
|
||||
import de.anomic.plasma.plasmaSearchQuery;
|
||||
import de.anomic.plasma.plasmaSnippetCache;
|
||||
import de.anomic.plasma.plasmaSwitchboard;
|
||||
import de.anomic.plasma.plasmaURL;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
import de.anomic.yacy.yacyCore;
|
||||
import de.anomic.yacy.yacySeed;
|
||||
|
||||
public class snippet {
|
||||
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) throws MalformedURLException {
|
||||
// return variable that accumulates replacements
|
||||
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
|
||||
serverObjects prop = new serverObjects();
|
||||
|
||||
// getting url
|
||||
String urlString = post.get("url", "");
|
||||
URL url = new URL(urlString);
|
||||
|
||||
String querystring = post.get("search", "").trim();
|
||||
if ((querystring.length() > 2) && (querystring.charAt(0) == '"') && (querystring.charAt(querystring.length() - 1) == '"')) {
|
||||
querystring = querystring.substring(1, querystring.length() - 1).trim();
|
||||
}
|
||||
final TreeSet query = plasmaSearchQuery.cleanQuery(querystring);
|
||||
|
||||
// filter out stopwords
|
||||
final TreeSet filtered = kelondroMSetTools.joinConstructive(query, plasmaSwitchboard.stopwords);
|
||||
if (filtered.size() > 0) {
|
||||
kelondroMSetTools.excludeDestructive(query, plasmaSwitchboard.stopwords);
|
||||
}
|
||||
|
||||
// do the search
|
||||
Set queryHashes = plasmaSearchQuery.words2hashes(query);
|
||||
|
||||
plasmaSnippetCache.result snippet = switchboard.snippetCache.retrieve(url, queryHashes, true, 260);
|
||||
prop.put("status",snippet.source);
|
||||
if (snippet.source < 11) {
|
||||
prop.put("text", (snippet.line != null)?snippet.line.trim():"unknown");
|
||||
} else {
|
||||
prop.put("text", (snippet.error != null)?snippet.error.trim():"unkown");
|
||||
}
|
||||
prop.put("urlHash",plasmaURL.urlHash(url));
|
||||
|
||||
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<snippet>
|
||||
<text>#[text]#</text>
|
||||
<status>#[status]#</status>
|
||||
<urlHash>#[urlHash]#</urlHash>
|
||||
</snippet>
|
Loading…
Reference in new issue