Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
first version of surftipps see http://localhost:8080/index.html
orbiterec031eb99376
diff --git a/htroot/index.html b/htroot/index.htmlindex d300b6bfa..41530f4bc 100644--- a/htroot/index.html+++ b/htroot/index.html@@ -107,6 +107,31 @@</table>#(/searchoptions)#</form>++ #(surftipps)#+ ::+ <h3>Surftipps</h3><br>+ provided by YaCy peers<br>+ #{results}#+ <!-- link begin -->+ <div class="searchresults">+ <div class="urlactions">+ <a href="/Bookmarks.html?edit=#[urlhash]#" class="bookmarklink" title="bookmark"><img src="/env/grafics/empty.gif" title="bookmark" alt="bookmark" class="bookmarkIcon" /></a>+ #(recommend)#+ <img src="/env/grafics/empty.gif" title="" alt="" class="recommendIcon" />+ <img src="/env/grafics/empty.gif" title="" alt="" class="deleteIcon" />+ ::+ <a href="#[positiveVoteLink]#" title="positive vote" class="recommendlink"><img src="/env/grafics/empty.gif" title="positive vote" alt="positive vote" class="recommendIcon" /></a>+ <a href="#[negativeVoteLink]#" title="negative vote" class="deletelink" ><img src="/env/grafics/empty.gif" title="negative vote" alt="negative vote" class="deleteIcon" /></a>+ #(/recommend)#+ </div>+ <h4 class="linktitle"><a href="#[url]#">#[title]#</a></h4>+ <p class="snippet">#[description]#</p>+ </div>+ <!-- link end -->+ #{/results}#+ #(/surftipps)#+#(display)##%env/templates/simplefooter.template%#::diff --git a/htroot/index.java b/htroot/index.javaindex abffc01d7..f4e3de385 100644--- a/htroot/index.java+++ b/htroot/index.java@@ -48,16 +48,25 @@import java.io.IOException;import java.net.MalformedURLException;-import de.anomic.net.URL;+import java.util.Date;import java.util.HashMap;+import java.util.Iterator;import de.anomic.http.httpHeader;+import de.anomic.kelondro.kelondroMScoreCluster;+import de.anomic.kelondro.kelondroRow;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSearchPreOrder;import de.anomic.server.serverCore;import de.anomic.server.serverDate;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.tools.nxTools;+import de.anomic.yacy.yacyCore;+import de.anomic.yacy.yacyNewsPool;+import de.anomic.yacy.yacyNewsRecord;+import de.anomic.yacy.yacySeed;+import de.anomic.net.URL;public class index {@@ -131,7 +140,97 @@ public class index {prop.put("depth", "0");prop.put("display", display);prop.put("searchoptions_display", display);+++ // create surftipps+ int maxCount = yacyCore.newsPool.size(yacyNewsPool.INCOMING_DB);+ if (maxCount > 300) maxCount = 300;+ kelondroMScoreCluster surftipps = new kelondroMScoreCluster();+ yacyNewsRecord record;+ kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120");+ for (int j = 0; j < maxCount; j++) try {+ record = yacyCore.newsPool.get(yacyNewsPool.INCOMING_DB, j);+ if (record == null) continue;++ if (record.category().equals("crwlstrt")) {+ String intention = record.attribute("intention", "");+ surftipps.setScore(+ rowdef.newEntry(new byte[][]{+ record.attribute("startURL", "").getBytes(),+ ((intention.length() == 0) ? record.attribute("startURL", "") : intention).getBytes(),+ ("Crawl Start Point").getBytes()+ }), 2 + Math.min(10, intention.length() / 4) + timeFactor(record.created()));+ }++ if (record.category().equals("prfleupd")) {+ surftipps.setScore(+ rowdef.newEntry(new byte[][]{+ record.attribute("homepage", "").getBytes(),+ ("Home Page of " + record.attribute("nickname", "")).getBytes(),+ ("Profile Update").getBytes()+ }), 1 + timeFactor(record.created()));+ }++ if (record.category().equals("bkmrkadd")) {+ surftipps.setScore(+ rowdef.newEntry(new byte[][]{+ record.attribute("url", "").getBytes(),+ (record.attribute("title", "")).getBytes(),+ ("Bookmark: " + record.attribute("description", "")).getBytes()+ }), 8 + timeFactor(record.created()));+ }++ if (record.category().equals("stippadd")) {+ surftipps.setScore(+ rowdef.newEntry(new byte[][]{+ record.attribute("url", "").getBytes(),+ (record.attribute("title", "")).getBytes(),+ ("Surf Tipp: " + record.attribute("description", "")).getBytes()+ }), 5 + timeFactor(record.created()));+ }++ if (record.category().equals("wiki_upd")) {+ yacySeed seed = yacyCore.seedDB.getConnected(record.originator());+ if (seed == null) seed = yacyCore.seedDB.getDisconnected(record.originator());+ if (seed != null) surftipps.setScore(+ rowdef.newEntry(new byte[][]{+ ("http://" + seed.getAddress() + "/Wiki.html?page=" + record.attribute("page", "")).getBytes(),+ (record.attribute("author", "Anonymous") + ": " + record.attribute("page", "")).getBytes(),+ ("Wiki Update: " + record.attribute("description", "")).getBytes()+ }), 4 + timeFactor(record.created()));+ }++ } catch (IOException e) {e.printStackTrace();}++ // read out surftipp array and create property entries+ Iterator k = surftipps.scores(false);+ int i = 0;+ kelondroRow.Entry row;+ while (k.hasNext()) {+ row = (kelondroRow.Entry) k.next();+ try {+ prop.put("surftipps_results_" + i + "_recommend", (yacyCore.newsPool.getSpecific(yacyNewsPool.OUTGOING_DB, "stippadd", "url", row.getColString(1, null)) == null) ? 1 : 0);+ prop.put("surftipps_results_" + i + "_recommend_deletelink", "/index.html?");+ prop.put("surftipps" + i + "_recommend_recommendlink", "/index.html?");+ prop.put("surftipps_results_" + i + "_url", row.getColString(0, null));+ prop.put("surftipps_results_" + i + "_urlname", nxTools.cutUrlText(row.getColString(0, null), 60));+ prop.put("surftipps_results_" + i + "_title", row.getColString(1, null));+ prop.put("surftipps_results_" + i + "_description", row.getColString(2, null));+ i++;+ } catch (IOException e) {+ e.printStackTrace();+ }+ if (i >= 50) break;+ }+ prop.put("surftipps_results", i);+ prop.put("surftipps", 1);++return prop;}+ private static int timeFactor(Date created) {+ return (int) Math.max(0, 10 - ((System.currentTimeMillis() - created.getTime()) / 24 / 60 / 60 / 1000));+ }+}diff --git a/source/de/anomic/http/httpTemplate.java b/source/de/anomic/http/httpTemplate.javaindex 3b68b69b4..702ff0374 100644--- a/source/de/anomic/http/httpTemplate.java+++ b/source/de/anomic/http/httpTemplate.java@@ -303,7 +303,7 @@ public final class httpTemplate {}//forstructure.append("</".getBytes("UTF-8")).append(multi_key).append(">\n".getBytes("UTF-8"));}else{//transferUntil- serverLog.logSevere("TEMPLATE", "No Close Key found for #{"+multi_key+"}#"); //prefix here?+ serverLog.logSevere("TEMPLATE", "No Close Key found for #{"+new String(multi_key)+"}#"); //prefix here?}}}else if( (bb & 0xFF) == lrbr ){ //alternatives@@ -357,7 +357,7 @@ public final class httpTemplate {structure.append(writeTemplate(pis2, out, pattern, dflt, newPrefix(prefix,key)));transferUntil(pis, keyStream, appendBytes("#(/".getBytes("UTF-8"),key,")#".getBytes("UTF-8"),null));if(pis.available()==0){- serverLog.logSevere("TEMPLATE", "No Close Key found for #("+key+")# (by Name)");+ serverLog.logSevere("TEMPLATE", "No Close Key found for #("+new String(key)+")# (by Name)");}}else{while(!found){@@ -412,7 +412,7 @@ public final class httpTemplate {if(!found){text.append((byte)bb);if(pis.available()==0){- serverLog.logSevere("TEMPLATE", "No Close Key found for #("+key+")# (by Index)");+ serverLog.logSevere("TEMPLATE", "No Close Key found for #("+new String(key)+")# (by Index)");found=true;}}diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.javaindex 650676883..846515795 100644--- a/source/de/anomic/kelondro/kelondroRow.java+++ b/source/de/anomic/kelondro/kelondroRow.java@@ -143,7 +143,7 @@ public class kelondroRow {return new Entry(external);}- public class Entry {+ public class Entry implements Comparable {private byte[] rowinstance;@@ -203,6 +203,13 @@ public class kelondroRow {}}+ public int compareTo(Object o) {+ if (o instanceof Entry) {+ return kelondroNaturalOrder.naturalOrder.compare(this.rowinstance, ((Entry) o).rowinstance);+ }+ throw new UnsupportedOperationException("works only for Entry objects");+ }+public byte[] bytes() {return rowinstance;}@@ -404,6 +411,7 @@ public class kelondroRow {public String toString() {return toPropertyForm(true, false, false);}+}public final static void long2bytes(long x, byte[] b, int offset, int length) {diff --git a/source/de/anomic/yacy/yacyNewsPool.java b/source/de/anomic/yacy/yacyNewsPool.javaindex 0a44d04bb..986cbd55a 100644--- a/source/de/anomic/yacy/yacyNewsPool.java+++ b/source/de/anomic/yacy/yacyNewsPool.java@@ -239,7 +239,7 @@ public class yacyNewsPool {}return null;}-+public synchronized yacyNewsRecord getByOriginator(int dbKey, String category, String originatorHash) throws IOException {yacyNewsQueue queue = switchQueue(dbKey);yacyNewsRecord record;@@ -253,7 +253,17 @@ public class yacyNewsPool {}return null;}-++ public synchronized yacyNewsRecord getByID(int dbKey, String id) throws IOException {+ switch (dbKey) {+ case INCOMING_DB: return incomingNews.get(id);+ case PROCESSED_DB: return processedNews.get(id);+ case OUTGOING_DB: return outgoingNews.get(id);+ case PUBLISHED_DB: return publishedNews.get(id);+ }+ return null;+ }+private yacyNewsQueue switchQueue(int dbKey) {switch (dbKey) {case INCOMING_DB: return incomingNews;@@ -279,7 +289,7 @@ public class yacyNewsPool {// this is called if a queue element shall be moved to another queue or off the queue// it depends on the dbKey how the record is handledswitch (dbKey) {- case INCOMING_DB: moveOff(incomingNews, processedNews, id); break;+ case INCOMING_DB: moveOff(incomingNews, processedNews, id); break;case PROCESSED_DB: moveOff(processedNews, null,id); break;case OUTGOING_DB: moveOff(outgoingNews, publishedNews, id); break;case PUBLISHED_DB: moveOff(publishedNews, null, id); break;diff --git a/source/de/anomic/yacy/yacyNewsQueue.java b/source/de/anomic/yacy/yacyNewsQueue.javaindex b34a86d3d..4e7d15dd3 100644--- a/source/de/anomic/yacy/yacyNewsQueue.java+++ b/source/de/anomic/yacy/yacyNewsQueue.java@@ -116,6 +116,15 @@ public class yacyNewsQueue {return entry;}+ public synchronized yacyNewsRecord get(String id) throws IOException {+ yacyNewsRecord record;+ for (int i = 0; i < size(); i++) {+ record = top(i);+ if ((record != null) && (record.id().equals(id))) return record;+ }+ return null;+ }+public synchronized yacyNewsRecord remove(String id) throws IOException {yacyNewsRecord record;for (int i = 0; i < size(); i++) {diff --git a/source/de/anomic/yacy/yacyNewsRecord.java b/source/de/anomic/yacy/yacyNewsRecord.javaindex 06644b0e3..d814ff950 100644--- a/source/de/anomic/yacy/yacyNewsRecord.java+++ b/source/de/anomic/yacy/yacyNewsRecord.java@@ -161,6 +161,12 @@ public class yacyNewsRecord {public Map attributes() {return attributes;}++ public String attribute(String key, String dflt) {+ String s = (String) attributes.get(key);+ if ((s == null) || (s.length() == 0)) return dflt;+ return s;+ }public static void main(String[] args) {System.out.println((new yacyNewsRecord(args[0])).toString());