- added option to localization search to distinguish between a search for a location according to the search word only or for the relation between a web search results and locations found in the metadata fields

- used that to display two layers on map: cities and search result locations
- added many marker grafics for the display of the markers on the map
- some refactoring of the yacy news code plus bugfixes for latest move from Tree to Table data structure

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6889 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent ad823a4716
commit 1defd580bc

@ -46,8 +46,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import java.util.List;
import java.util.Map;
@ -175,7 +175,7 @@ public class Blog {
map.put("page", pagename);
map.put("subject", StrSubject.replace(',', ' '));
map.put("author", StrAuthor.replace(',', ' '));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BLOG_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BLOG_ADD, map));
}
page = sb.blogDB.readBlogEntry(pagename); //maybe "if(page == null)"

@ -52,8 +52,8 @@ import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class Bookmarks {
@ -434,7 +434,7 @@ public class Bookmarks {
map.put("title", title.replace(',', ' '));
map.put("description", description.replace(',', ' '));
map.put("tags", tagsString.replace(',', ' '));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
}
}

@ -39,8 +39,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class ConfigProfile_p {
@ -94,7 +94,7 @@ public class ConfigProfile_p {
// generate a news message
final Properties news = profile;
news.remove("comment");
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
sb.peers.newsPool.publishMyNews(yacyNewsDB.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_PROFILE_UPDATE, news));
//yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsRecord.CATEGORY_PROFILE_UPDATE, profile));
} catch(final IOException e) {
} finally {

@ -30,8 +30,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
public class CrawlMonitorRemoteStart {
@ -44,9 +44,9 @@ public class CrawlMonitorRemoteStart {
boolean dark = true;
// create other peer crawl table using YaCyNews
Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(yacyNewsPool.INCOMING_DB, true);
Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(yacyNewsPool.INCOMING_DB, true);
int showedCrawl = 0;
yacyNewsRecord record;
yacyNewsDB.Record record;
yacySeed peer;
String peername;
while (recordIterator.hasNext()) {

@ -56,8 +56,8 @@ import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class Crawler_p {
public static final String CRAWLING_MODE_URL = "url";
@ -288,7 +288,7 @@ public class Crawler_p {
m.remove("generalFilter");
m.remove("specificFilter");
m.put("intention", post.get("intention", "").replace(',', '/'));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_CRAWL_START, m));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_CRAWL_START, m));
}
} else {
prop.put("info", "5"); //Crawling failed

@ -48,8 +48,8 @@ import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyClient;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacyVersion;
@ -244,8 +244,8 @@ public class Network {
final HashMap<String, Map<String, String>> updatedWiki = new HashMap<String, Map<String, String>>();
final HashMap<String, Map<String, String>> updatedBlog = new HashMap<String, Map<String, String>>();
final HashMap<String, String> isCrawling = new HashMap<String, String>();
yacyNewsRecord record;
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(yacyNewsPool.INCOMING_DB, true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(yacyNewsPool.INCOMING_DB, true);
while (recordIterator.hasNext()) {
record = recordIterator.next();
if (record == null) {

@ -35,8 +35,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
public class News {
@ -103,8 +103,8 @@ public class News {
if (sb.peers != null) {
final int maxCount = Math.min(1000, sb.peers.newsPool.size(tableID));
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(tableID, false);
yacyNewsRecord record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(tableID, false);
yacyNewsDB.Record record;
yacySeed seed;
int i = 0;
while ((recordIterator.hasNext()) && (i < maxCount)) {

@ -45,8 +45,8 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
import de.anomic.tools.nxTools;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
public class Supporter {
@ -79,7 +79,7 @@ public class Supporter {
map.put("urlhash", hash);
map.put("vote", "negative");
map.put("refid", post.get("refid", ""));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {
if (!sb.verifyAuthentication(header, false)) {
@ -95,7 +95,7 @@ public class Supporter {
map.put("vote", "positive");
map.put("refid", post.get("refid", ""));
map.put("comment", post.get("comment", ""));
sb.peers.newsPool.publishMyNews(new yacyNewsRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
// create Supporter
@ -170,8 +170,8 @@ public class Supporter {
private static void accumulateVotes(final Switchboard sb, final HashMap<String, Integer> negativeHashes, final HashMap<String, Integer> positiveHashes, final int dbtype) {
final int maxCount = Math.min(1000, sb.peers.newsPool.size(dbtype));
yacyNewsRecord record;
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
int j = 0;
while ((recordIterator.hasNext()) && (j++ < maxCount)) {
record = recordIterator.next();
@ -200,8 +200,8 @@ public class Supporter {
final HashMap<String, Entry> Supporter, final ScoreCluster<String> ranking, final Row rowdef,
final HashMap<String, Integer> negativeHashes, final HashMap<String, Integer> positiveHashes, final int dbtype) {
final int maxCount = Math.min(1000, sb.peers.newsPool.size(dbtype));
yacyNewsRecord record;
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
int j = 0;
String url = "", urlhash;
Row.Entry entry;

@ -45,8 +45,8 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
import de.anomic.tools.nxTools;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
public class Surftips {
@ -87,7 +87,7 @@ public class Surftips {
map.put("urlhash", hash);
map.put("vote", "negative");
map.put("refid", post.get("refid", ""));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {
if (!sb.verifyAuthentication(header, false)) {
@ -103,7 +103,7 @@ public class Surftips {
map.put("vote", "positive");
map.put("refid", post.get("refid", ""));
map.put("comment", post.get("comment", ""));
sb.peers.newsPool.publishMyNews(new yacyNewsRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
}
// create surftips
@ -179,8 +179,8 @@ public class Surftips {
private static void accumulateVotes(final Switchboard sb, final HashMap<String, Integer> negativeHashes, final HashMap<String, Integer> positiveHashes, final int dbtype) {
final int maxCount = Math.min(1000, sb.peers.newsPool.size(dbtype));
yacyNewsRecord record;
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
int j = 0;
while ((recordIterator.hasNext()) && (j++ < maxCount)) {
record = recordIterator.next();
@ -209,8 +209,8 @@ public class Surftips {
final HashMap<String, Entry> surftips, final ScoreCluster<String> ranking, final Row rowdef,
final HashMap<String, Integer> negativeHashes, final HashMap<String, Integer> positiveHashes, final int dbtype) {
final int maxCount = Math.min(1000, sb.peers.newsPool.size(dbtype));
yacyNewsRecord record;
final Iterator<yacyNewsRecord> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> recordIterator = sb.peers.newsPool.recordIterator(dbtype, true);
int j = 0;
String url = "", urlhash;
Row.Entry entry;

@ -50,8 +50,8 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyClient;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
public class ViewProfile {
@ -99,7 +99,7 @@ public class ViewProfile {
} else {
// process news if existent
try {
final yacyNewsRecord record = sb.peers.newsPool.getByOriginator(yacyNewsPool.INCOMING_DB, yacyNewsPool.CATEGORY_PROFILE_UPDATE, seed.hash);
final yacyNewsDB.Record record = sb.peers.newsPool.getByOriginator(yacyNewsPool.INCOMING_DB, yacyNewsPool.CATEGORY_PROFILE_UPDATE, seed.hash);
if (record != null) sb.peers.newsPool.moveOff(yacyNewsPool.INCOMING_DB, record.id());
} catch (final Exception e) {
Log.logException(e);

@ -45,8 +45,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class Wiki {
@ -121,7 +121,7 @@ public class Wiki {
map.put("page", pagename);
map.put("author", author.replace(',', ' '));
if (post.get("content", "").trim().length() > 0 && !page.page().equals(content))
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_WIKI_UPDATE, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_WIKI_UPDATE, map));
page = newEntry;
prop.putHTML("LOCATION", "/Wiki.html?page=" + pagename);
}

@ -10,8 +10,8 @@ import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class add_p {
@ -83,6 +83,6 @@ public class add_p {
map.put("title", title.replace(',', ' '));
map.put("description", description.replace(',', ' '));
map.put("tags", tagsString.replace(',', ' '));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

@ -68,8 +68,8 @@ import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.graphics.ProfilingGraph;
public class yacysearch {
@ -413,7 +413,7 @@ public class yacysearch {
map.put("urlhash", delHash);
map.put("vote", "negative");
map.put("refid", "");
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));
} catch (IOException e) {
Log.logException(e);
}
@ -438,7 +438,7 @@ public class yacysearch {
map.put("description", document.dc_title().replace(',', ' '));
map.put("author", document.dc_creator());
map.put("tags", document.dc_subject(' '));
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_ADD, map));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_ADD, map));
document.close();
}
}

@ -7,7 +7,13 @@
<script type="text/javascript" src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript">
var map;
var searchLayer = null;
var searchLayer_md = null;
var searchLayer_co = null;
var path_mdsearch = 'yacysearch_location.rss?dom=title,publisher,creator,subject&query=';
var path_cosearch = 'yacysearch_location.rss?dom=query&query=';
var marker_md = new OpenLayers.Icon("/env/grafics/marker_red.png", new OpenLayers.Size(11,16));
var marker_co = new OpenLayers.Icon("/env/grafics/star_yellow.png", new OpenLayers.Size(25,25));
// possible values for dom: query,mdall,title,publisher,creator,subject
function init() {
map = new OpenLayers.Map('map', {
@ -22,14 +28,14 @@
layerMaplint = new OpenLayers.Layer.OSM.Maplint("Maplint");
layerWMS = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
layerOsmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
map.addLayer(layerMapnik);
map.addLayer(layerOsmarender);
map.addLayer(layerCycleMap);
map.addLayer(layerMaplint);
map.addLayer(layerWMS);
map.addLayer(layerMapnik);
map.addLayer(layerTilesAtHome);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(0,0) // Center of the map
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
@ -38,16 +44,21 @@
);
#(initsearch)#::
searchLayer = new OpenLayers.Layer.GeoRSS('GeoRSS', 'yacysearch_location.rss?query=#[query]#');
map.addLayer(searchLayer);
searchLayer_co = new OpenLayers.Layer.GeoRSS('GeoRSS', path_cosearch + '#[query]#', {'icon':marker_co});
map.addLayer(searchLayer_co);
searchLayer_md = new OpenLayers.Layer.GeoRSS('GeoRSS', path_mdsearch + '#[query]#', {'icon':marker_md});
map.addLayer(searchLayer_md);
#(/initsearch)#
}
function search() {
var query = document.getElementById('query').value.replace(' ', '+');
if (searchLayer != null) searchLayer.destroy();
searchLayer = new OpenLayers.Layer.GeoRSS('GeoRSS', 'yacysearch_location.rss?query=' + query);
map.addLayer(searchLayer);
if (searchLayer_md != null) searchLayer_md.destroy();
if (searchLayer_co != null) searchLayer_co.destroy();
searchLayer_co = new OpenLayers.Layer.GeoRSS('GeoRSS', path_cosearch + query, {'icon':marker_co});
map.addLayer(searchLayer_co);
searchLayer_md = new OpenLayers.Layer.GeoRSS('GeoRSS', path_mdsearch + query, {'icon':marker_md});
map.addLayer(searchLayer_md);
}
</script>

@ -33,13 +33,16 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyClient;
import java.util.Date;
import net.yacy.kelondro.util.DateFormatter;
public class yacysearch_location {
private static final String space = " ";
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
//final Switchboard sb = (Switchboard) env;
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
prop.put("kml", 0);
@ -52,33 +55,61 @@ public class yacysearch_location {
prop.put("kml", 1);
if (post == null) return prop;
String query = post.get("query", "");
boolean search_all = !post.containsKey("dom") || post.get("dom", "").equals("all");
boolean search_query = search_all || post.get("dom", "").indexOf("query") >= 0;
boolean search_mdall = search_all || post.get("dom", "").indexOf("mdall") >= 0;
boolean search_title = search_mdall || post.get("dom", "").indexOf("title") >= 0;
boolean search_publisher = search_mdall || post.get("dom", "").indexOf("publisher") >= 0;
boolean search_creator = search_mdall || post.get("dom", "").indexOf("creator") >= 0;
boolean search_subject = search_mdall || post.get("dom", "").indexOf("subject") >= 0;
long maximumTime = post.getLong("maximumTime", 1000);
int maximumRecords = post.getInt("maximumRecords", 100);
//i.e. http://localhost:8080/yacysearch_location.kml?query=berlin&maximumTime=2000&maximumRecords=100
// get a queue of search results
BlockingQueue<RSSMessage> results = yacyClient.search(null, query, false, false, maximumTime, Integer.MAX_VALUE);
// take the results and compute some locations
RSSMessage message;
int placemarkCounter = 0;
try {
if (search_query) {
Set<Location> locations = LibraryProvider.geoLoc.find(query, true);
for (Location location: locations) {
// write for all locations a point to this message
prop.put("kml_placemark_" + placemarkCounter + "_location", location.getName());
prop.put("kml_placemark_" + placemarkCounter + "_name", location.getName());
prop.put("kml_placemark_" + placemarkCounter + "_author", "");
prop.put("kml_placemark_" + placemarkCounter + "_copyright", "");
prop.put("kml_placemark_" + placemarkCounter + "_subject", "");
prop.put("kml_placemark_" + placemarkCounter + "_description", "");
prop.put("kml_placemark_" + placemarkCounter + "_date", "");
prop.putXML("kml_placemark_" + placemarkCounter + "_url", "http://" + sb.peers.mySeed().getPublicAddress() + "/yacysearch.html?query=" + location.getName());
prop.put("kml_placemark_" + placemarkCounter + "_pointname", location.getName());
prop.put("kml_placemark_" + placemarkCounter + "_lon", location.lon());
prop.put("kml_placemark_" + placemarkCounter + "_lat", location.lat());
placemarkCounter++;
}
}
if (search_title || search_publisher || search_creator || search_subject) try {
// get a queue of search results
BlockingQueue<RSSMessage> results = yacyClient.search(null, query, false, false, maximumTime, Integer.MAX_VALUE);
// take the results and compute some locations
RSSMessage message;
loop: while ((message = results.poll(maximumTime, TimeUnit.MILLISECONDS)) != RSSMessage.POISON) {
// find all associated locations
Set<Location> locations = new HashSet<Location>();
String words = message.getTitle() + " " + message.getCopyright() + " " + message.getAuthor();
StringBuilder words = new StringBuilder(120);
if (search_title) words.append(message.getTitle().trim()).append(space);
if (search_publisher) words.append(message.getCopyright().trim()).append(space);
if (search_creator) words.append(message.getAuthor().trim()).append(space);
String subject = "";
for (String s: message.getSubject()) subject += " " + s;
words += subject;
for (String word: words.split(" ")) if (word.length() >= 3) locations.addAll(LibraryProvider.geoLoc.find(word, true));
String locnames = "";
for (Location location: locations) locnames += ", " + location.getName();
if (locations.size() > 0) locnames = locnames.substring(2);
for (String s: message.getSubject()) subject += s.trim() + space;
if (search_subject) words.append(subject).append(space);
String[] wordlist = words.toString().trim().split(space);
for (String word: wordlist) if (word.length() >= 3) locations.addAll(LibraryProvider.geoLoc.find(word, true));
for (int i = 0; i < wordlist.length - 1; i++) locations.addAll(LibraryProvider.geoLoc.find(wordlist[i] + space + wordlist[i + 1], true));
for (int i = 0; i < wordlist.length - 2; i++) locations.addAll(LibraryProvider.geoLoc.find(wordlist[i] + space + wordlist[i + 1] + space + wordlist[i + 2], true));
for (Location location: locations) {
// write for all locations a point to this message
prop.put("kml_placemark_" + placemarkCounter + "_location", locnames);
prop.put("kml_placemark_" + placemarkCounter + "_location", location.getName());
prop.put("kml_placemark_" + placemarkCounter + "_name", message.getTitle());
prop.put("kml_placemark_" + placemarkCounter + "_author", message.getAuthor());
prop.put("kml_placemark_" + placemarkCounter + "_copyright", message.getCopyright());
@ -93,8 +124,8 @@ public class yacysearch_location {
if (placemarkCounter >= maximumRecords) break loop;
}
}
prop.put("kml_placemark", placemarkCounter);
} catch (InterruptedException e) {}
prop.put("kml_placemark", placemarkCounter);
}
if (header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("rss")) {
if (post == null) return prop;
@ -117,7 +148,6 @@ public class yacysearch_location {
}
if (header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("html")) {
final Switchboard sb = (Switchboard) env;
final boolean authenticated = sb.adminAuthenticated(header) >= 2;
int display = (post == null) ? 0 : post.getInt("display", 0);
if (!authenticated) display = 2;

@ -44,8 +44,10 @@
</div>
#(/nav-about)#
#(cat-location)#::
<div id="sidebar4" style="float: right; margin-top:5px; width: 220px;">
<div><a href="yacysearch_location.html?query=#[query]#&display=#[display]#"><img src="/env/grafics/earthsearch.png"></a><h4><a href="yacysearch_location.html?query=#[query]#&display=#[display]#">Show search results for "#[query]#" on map!</a></h4>
<div><a href="yacysearch_location.html?query=#[query]#&display=#[display]#">
<img src="/env/grafics/earthsearch.png"></a></div>
<div><a href="yacysearch_location.html?query=#[query]#&display=#[display]#">Show search results for "#[query]#" on map!</a></div>
</div>
</div>
#(/cat-location)#

@ -30,6 +30,7 @@ import java.util.List;
import net.yacy.kelondro.util.EventTracker;
import de.anomic.data.LibraryProvider;
import de.anomic.http.server.RequestHeader;
import de.anomic.search.Navigator;
import de.anomic.search.QueryParams;
@ -169,9 +170,16 @@ public class yacysearchtrailer {
prop.put("nav-about_body", aboutBody);
}
// location search
prop.put("query", theQuery.queryString);
prop.put("display", display);
// category: location search
// show only if there is a location database present and if there had been any search results
if (LibraryProvider.geoLoc.locations() == 0 ||
theSearch.getRankingResult().getLocalIndexCount() == 0) {
prop.put("cat-location", 0);
} else {
prop.put("cat-location", 1);
prop.put("cat-location_query", theQuery.queryString);
prop.put("cat-location_display", display);
}
EventTracker.update("SEARCH", new ProfilingGraph.searchEvent(theQuery.id(true), SearchEvent.FINALIZATION + "-" + "bottomline", 0, 0), false, 30000, ProfilingGraph.maxTime);

@ -56,8 +56,8 @@ import de.anomic.crawler.CrawlProfile;
import de.anomic.crawler.retrieval.Request;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
public class bookmarksDB {
// ------------------------------------
@ -291,7 +291,7 @@ public class bookmarksDB {
m.remove("generalFilter");
m.remove("specificFilter");
m.put("intention", "Automatic ReCrawl!");
sb.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.peers.mySeed(), yacyNewsPool.CATEGORY_CRAWL_START, m));
sb.peers.newsPool.publishMyNews(new yacyNewsDB.Record(sb.peers.mySeed(), yacyNewsPool.CATEGORY_CRAWL_START, m));
}
} catch (MalformedURLException e1) {}
} // if

@ -149,8 +149,8 @@ import de.anomic.tools.CryptoLib;
import de.anomic.yacy.yacyBuildProperties;
import de.anomic.yacy.yacyClient;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.Tray;
import de.anomic.yacy.yacySeedDB;
@ -1607,7 +1607,7 @@ public final class Switchboard extends serverSwitch {
if ((homepage != null) && (homepage.length() > 10)) {
final Properties news = new Properties();
news.put("homepage", profile.get("homepage"));
this.peers.newsPool.publishMyNews(yacyNewsRecord.newRecord(peers.mySeed(), yacyNewsPool.CATEGORY_PROFILE_BROADCAST, news));
this.peers.newsPool.publishMyNews(yacyNewsDB.newRecord(peers.mySeed(), yacyNewsPool.CATEGORY_PROFILE_BROADCAST, news));
}
}

@ -346,7 +346,7 @@ public class yacyCore {
// include a YaCyNews record to my seed
try {
final yacyNewsRecord record = sb.peers.newsPool.myPublication();
final yacyNewsDB.Record record = sb.peers.newsPool.myPublication();
if (record == null) {
sb.peers.mySeed().put("news", "");
} else {

@ -47,13 +47,20 @@ package de.anomic.yacy;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.ObjectIndex;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.table.Table;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
@ -66,16 +73,36 @@ public class yacyNewsDB {
private final File path;
protected ObjectIndex news;
private static final int maxNewsRecordLength = 512;
private static final int categoryStringLength = 8;
public static final int idLength = DateFormatter.PATTERN_SHORT_SECOND.length() + Word.commonHashLength;
private static final int attributesMaxLength =
maxNewsRecordLength
- idLength
- categoryStringLength
- DateFormatter.PATTERN_SHORT_SECOND.length()
- 2;
private static final Row rowdef = new Row(
"String idx-" + idLength + " \"id = created + originator\"," +
"String cat-" + categoryStringLength + "," +
"String rec-" + DateFormatter.PATTERN_SHORT_SECOND.length() + "," +
"short dis-2 {b64e}," +
"String att-" + attributesMaxLength,
NaturalOrder.naturalOrder
);
public yacyNewsDB(
final File path,
final boolean useTailCache,
final boolean exceed134217727) {
this.path = path;
try {
this.news = new Table(path, yacyNewsRecord.rowdef, 10, 0, useTailCache, exceed134217727);
this.news = new Table(path, rowdef, 10, 0, useTailCache, exceed134217727);
} catch (RowSpaceExceededException e) {
try {
this.news = new Table(path, yacyNewsRecord.rowdef, 0, 0, false, exceed134217727);
this.news = new Table(path, rowdef, 0, 0, false, exceed134217727);
} catch (RowSpaceExceededException e1) {
Log.logException(e1);
}
@ -86,10 +113,10 @@ public class yacyNewsDB {
try {close();} catch (final Exception e) {}
if (path.exists()) FileUtils.deletedelete(path);
try {
this.news = new Table(path, yacyNewsRecord.rowdef, 10, 0, false, false);
this.news = new Table(path, rowdef, 10, 0, false, false);
} catch (RowSpaceExceededException e) {
try {
this.news = new Table(path, yacyNewsRecord.rowdef, 0, 0, false, false);
this.news = new Table(path, rowdef, 0, 0, false, false);
} catch (RowSpaceExceededException e1) {
Log.logException(e1);
}
@ -113,7 +140,7 @@ public class yacyNewsDB {
news.delete(id.getBytes());
}
public synchronized yacyNewsRecord put(final yacyNewsRecord record) throws IOException, RowSpaceExceededException {
public synchronized Record put(final Record record) throws IOException, RowSpaceExceededException {
try {
return b2r(news.replace(r2b(record)));
} catch (final Exception e) {
@ -122,12 +149,12 @@ public class yacyNewsDB {
}
}
public synchronized Iterator<yacyNewsRecord> news() throws IOException {
public synchronized Iterator<Record> news() throws IOException {
// the iteration iterates yacyNewsRecord - type objects
return new recordIterator();
}
public class recordIterator implements Iterator<yacyNewsRecord> {
public class recordIterator implements Iterator<Record> {
Iterator<Row.Entry> rowIterator;
@ -139,17 +166,17 @@ public class yacyNewsDB {
return rowIterator.hasNext();
}
public yacyNewsRecord next() {
public Record next() {
return b2r(rowIterator.next());
}
public void remove() {
throw new UnsupportedOperationException();
rowIterator.remove();
}
}
public synchronized yacyNewsRecord get(final String id) throws IOException {
public synchronized Record get(final String id) throws IOException {
try {
return b2r(news.get(id.getBytes()));
} catch (final kelondroException e) {
@ -158,9 +185,9 @@ public class yacyNewsDB {
}
}
protected final static yacyNewsRecord b2r(final Row.Entry b) {
protected final static Record b2r(final Row.Entry b) {
if (b == null) return null;
return yacyNewsRecord.newRecord(
return new yacyNewsDB.Record(
b.getColString(0, null),
b.getColString(1, "UTF-8"),
(b.empty(2)) ? null : DateFormatter.parseShortSecond(b.getColString(2, null), DateFormatter.UTCDiffString()),
@ -169,11 +196,11 @@ public class yacyNewsDB {
);
}
protected final Row.Entry r2b(final yacyNewsRecord r) {
protected final Row.Entry r2b(final Record r) {
if (r == null) return null;
try {
final String attributes = r.attributes().toString();
if (attributes.length() > yacyNewsRecord.attributesMaxLength) throw new IllegalArgumentException("attribute length=" + attributes.length() + " exceeds maximum size=" + yacyNewsRecord.attributesMaxLength);
if (attributes.length() > attributesMaxLength) throw new IllegalArgumentException("attribute length=" + attributes.length() + " exceeds maximum size=" + attributesMaxLength);
final Row.Entry entry = this.news.row().newEntry();
entry.setCol(0, r.id().getBytes());
entry.setCol(1, r.category().getBytes("UTF-8"));
@ -186,5 +213,131 @@ public class yacyNewsDB {
return null;
}
}
public static Record newRecord(final yacySeed mySeed, final String category, final Properties attributes) {
try {
final HashMap<String, String> m = new HashMap<String, String>();
final Iterator<Entry<Object, Object>> e = attributes.entrySet().iterator();
Map.Entry<Object, Object> entry;
while (e.hasNext()) {
entry = e.next();
m.put((String) entry.getKey(), (String) entry.getValue());
}
return new Record(mySeed, category, m);
} catch (final IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static class Record {
private final String originator; // hash of originating peer
private final Date created; // Date when news was created by originator
private final Date received; // Date when news was received here at this peer
private final String category; // keyword that adresses possible actions
private int distributed; // counter that counts number of distributions of this news record
private final Map<String, String> attributes; // elemets of the news for a special category
public Record(final String newsString) {
this.attributes = MapTools.string2map(newsString, ",");
if (attributes.toString().length() > yacyNewsDB.attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + yacyNewsDB.attributesMaxLength + ")");
this.category = (attributes.containsKey("cat")) ? attributes.get("cat") : "";
if (category.length() > yacyNewsDB.categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + yacyNewsDB.categoryStringLength + ")");
this.received = (attributes.containsKey("rec")) ? DateFormatter.parseShortSecond(attributes.get("rec"), DateFormatter.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? DateFormatter.parseShortSecond(attributes.get("cre"), DateFormatter.UTCDiffString()) : new Date();
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt(attributes.get("dis")) : 0;
this.originator = (attributes.containsKey("ori")) ? attributes.get("ori") : "";
removeStandards();
}
public Record(final yacySeed mySeed, final String category, final Map<String, String> attributes) {
if (category.length() > yacyNewsDB.categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + yacyNewsDB.categoryStringLength + ")");
if (attributes.toString().length() > yacyNewsDB.attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + yacyNewsDB.attributesMaxLength + ")");
this.attributes = attributes;
this.received = null;
this.created = new Date();
this.category = category;
this.distributed = 0;
this.originator = mySeed.hash;
removeStandards();
}
protected Record(final String id, final String category, final Date received, final int distributed, final Map<String, String> attributes) {
if (category.length() > yacyNewsDB.categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + yacyNewsDB.categoryStringLength + ")");
if (attributes.toString().length() > yacyNewsDB.attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + yacyNewsDB.attributesMaxLength + ")");
this.attributes = attributes;
this.received = received;
this.created = DateFormatter.parseShortSecond(id.substring(0, DateFormatter.PATTERN_SHORT_SECOND.length()), DateFormatter.UTCDiffString());
this.category = category;
this.distributed = distributed;
this.originator = id.substring(DateFormatter.PATTERN_SHORT_SECOND.length());
removeStandards();
}
private void removeStandards() {
attributes.remove("ori");
attributes.remove("cat");
attributes.remove("cre");
attributes.remove("rec");
attributes.remove("dis");
}
public String toString() {
// this creates the string that shall be distributed
// attention: this has no additional encoding
if (this.originator != null) attributes.put("ori", this.originator);
if (this.category != null) attributes.put("cat", this.category);
if (this.created != null) attributes.put("cre", DateFormatter.formatShortSecond(this.created));
if (this.received != null) attributes.put("rec", DateFormatter.formatShortSecond(this.received));
attributes.put("dis", Integer.toString(this.distributed));
final String theString = attributes.toString();
removeStandards();
return theString;
}
public String id() {
return DateFormatter.formatShortSecond(created) + originator;
}
public String originator() {
return originator;
}
public Date created() {
return created;
}
public Date received() {
return received;
}
public String category() {
return category;
}
public int distributed() {
return distributed;
}
public void incDistribution() {
distributed++;
}
public Map<String, String> attributes() {
return attributes;
}
public String attribute(final String key, final String dflt) {
final String s = attributes.get(key);
if ((s == null) || (s.length() == 0)) return dflt;
return s;
}
public static void main(final String[] args) {
System.out.println((new yacyNewsDB.Record(args[0])).toString());
}
}
}

@ -291,13 +291,13 @@ public class yacyNewsPool {
return newsDB.size();
}
public Iterator<yacyNewsRecord> recordIterator(final int dbKey, final boolean up) {
public Iterator<yacyNewsDB.Record> recordIterator(final int dbKey, final boolean up) {
// returns an iterator of yacyNewsRecord-type objects
final yacyNewsQueue queue = switchQueue(dbKey);
return queue.records(up);
}
public void publishMyNews(final yacyNewsRecord record) {
public void publishMyNews(final yacyNewsDB.Record record) {
// this shall be called if our peer generated a new news record and wants to publish it
if (record == null) return;
try {
@ -310,23 +310,29 @@ public class yacyNewsPool {
}
}
public yacyNewsRecord myPublication() throws IOException, RowSpaceExceededException {
public yacyNewsDB.Record myPublication() throws IOException, RowSpaceExceededException {
// generate a record for next peer-ping
if (outgoingNews.isEmpty()) return null;
final yacyNewsRecord record = outgoingNews.topInc();
if ((record != null) && (record.distributed() >= maxDistribution)) {
final yacyNewsDB.Record record = outgoingNews.pop();
if (record == null) return null;
record.incDistribution();
if (record.distributed() >= maxDistribution) {
// move record to its final position. This is only for history
publishedNews.push(outgoingNews.pop());
publishedNews.push(record);
} else {
outgoingNews.push(record);
}
return record;
}
public void enqueueIncomingNews(final yacyNewsRecord record) throws IOException, RowSpaceExceededException {
public void enqueueIncomingNews(final yacyNewsDB.Record record) throws IOException, RowSpaceExceededException {
// called if a news is attached to a seed
// check consistency
if (record.id() == null) return;
if (record.id().length() != yacyNewsRecord.idLength) return;
if (record.id().length() != yacyNewsDB.idLength) return;
if (record.category() == null) return;
if (!(categories.contains(record.category()))) return;
if (record.created().getTime() == 0) return;
@ -359,10 +365,11 @@ public class yacyNewsPool {
public int automaticProcess(final yacySeedDB seedDB) throws IOException, InterruptedException, RowSpaceExceededException {
// processes news in the incoming-db
// returns number of processes
yacyNewsRecord record;
yacyNewsDB.Record record;
int pc = 0;
synchronized (this.incomingNews) {
final Iterator<yacyNewsRecord> i = incomingNews.records(true);
final Iterator<yacyNewsDB.Record> i = incomingNews.records(true);
HashSet<String> removeIDs = new HashSet<String>();
while (i.hasNext()) {
// check for interruption
if (Thread.currentThread().isInterrupted()) throw new InterruptedException("Shutdown in progress");
@ -371,16 +378,17 @@ public class yacyNewsPool {
record = i.next();
if (automaticProcessP(seedDB, record)) {
this.processedNews.push(record);
i.remove();
removeIDs.add(record.id());
pc++;
}
}
for (String id: removeIDs) incomingNews.remove(id);
}
return pc;
}
long day = 1000 * 60 * 60 * 24;
private boolean automaticProcessP(final yacySeedDB seedDB, final yacyNewsRecord record) {
private boolean automaticProcessP(final yacySeedDB seedDB, final yacyNewsDB.Record record) {
if (record == null) return false;
if (record.category() == null) return true;
if ((System.currentTimeMillis() - record.created().getTime()) > (14 * day)) {
@ -412,11 +420,11 @@ public class yacyNewsPool {
return false;
}
public synchronized yacyNewsRecord getSpecific(final int dbKey, final String category, final String key, final String value) {
public synchronized yacyNewsDB.Record getSpecific(final int dbKey, final String category, final String key, final String value) {
final yacyNewsQueue queue = switchQueue(dbKey);
yacyNewsRecord record;
yacyNewsDB.Record record;
String s;
final Iterator<yacyNewsRecord> i = queue.records(true);
final Iterator<yacyNewsDB.Record> i = queue.records(true);
while (i.hasNext()) {
record = i.next();
if ((record != null) && (record.category().equals(category))) {
@ -427,10 +435,10 @@ public class yacyNewsPool {
return null;
}
public synchronized yacyNewsRecord getByOriginator(final int dbKey, final String category, final String originatorHash) {
public synchronized yacyNewsDB.Record getByOriginator(final int dbKey, final String category, final String originatorHash) {
final yacyNewsQueue queue = switchQueue(dbKey);
yacyNewsRecord record;
final Iterator<yacyNewsRecord> i = queue.records(true);
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> i = queue.records(true);
while (i.hasNext()) {
record = i.next();
if ((record != null) &&
@ -442,7 +450,7 @@ public class yacyNewsPool {
return null;
}
public synchronized yacyNewsRecord getByID(final int dbKey, final String id) {
public synchronized yacyNewsDB.Record getByID(final int dbKey, final String id) {
switch (dbKey) {
case INCOMING_DB: return incomingNews.get(id);
case PROCESSED_DB: return processedNews.get(id);
@ -485,7 +493,7 @@ public class yacyNewsPool {
private boolean moveOff(final yacyNewsQueue fromqueue, final yacyNewsQueue toqueue, final String id) throws IOException, RowSpaceExceededException {
// called if a published news shall be removed
final yacyNewsRecord record = fromqueue.remove(id);
final yacyNewsDB.Record record = fromqueue.remove(id);
if (record == null) {
return false;
}
@ -510,8 +518,8 @@ public class yacyNewsPool {
private int moveOffAll(final yacyNewsQueue fromqueue, final yacyNewsQueue toqueue) throws IOException, RowSpaceExceededException {
// move off all news from a specific queue to another queue
final Iterator<yacyNewsRecord> i = fromqueue.records(true);
yacyNewsRecord record;
final Iterator<yacyNewsDB.Record> i = fromqueue.records(true);
yacyNewsDB.Record record;
if (toqueue == null) return 0;
int c = 0;
while (i.hasNext()) {

@ -67,7 +67,7 @@ public class yacyNewsQueue {
private final yacyNewsDB newsDB;
public static final Row rowdef = new Row(new Column[]{
new Column("newsid", Column.celltype_string, Column.encoder_bytes, yacyNewsRecord.idLength, "id = created + originator"),
new Column("newsid", Column.celltype_string, Column.encoder_bytes, yacyNewsDB.idLength, "id = created + originator"),
new Column("last touched", Column.celltype_string, Column.encoder_bytes, DateFormatter.PATTERN_SHORT_SECOND.length(), "")
},
NaturalOrder.naturalOrder
@ -83,22 +83,22 @@ public class yacyNewsQueue {
this.queueStack = null;
}
}
private void resetDB() {
try {close();} catch (final Exception e) {}
if (path.exists()) FileUtils.deletedelete(path);
public void clear() {
try {
this.queueStack = new Table(path, rowdef, 10, 0, false, false);
} catch (RowSpaceExceededException e) {
Log.logException(e);
this.queueStack = null;
this.queueStack.clear();
} catch (IOException e) {
try {close();} catch (final Exception ee) {}
if (path.exists()) FileUtils.deletedelete(path);
try {
this.queueStack = new Table(path, rowdef, 10, 0, false, false);
} catch (RowSpaceExceededException ee) {
Log.logException(e);
this.queueStack = null;
}
}
}
public void clear() {
resetDB();
}
public void close() {
if (queueStack != null) queueStack.close();
queueStack = null;
@ -116,28 +116,18 @@ public class yacyNewsQueue {
return queueStack.isEmpty();
}
public synchronized void push(final yacyNewsRecord entry) throws IOException, RowSpaceExceededException {
public synchronized void push(final yacyNewsDB.Record entry) throws IOException, RowSpaceExceededException {
queueStack.addUnique(r2b(entry, true));
}
public synchronized yacyNewsRecord pop() throws IOException {
public synchronized yacyNewsDB.Record pop() throws IOException {
if (queueStack.isEmpty()) return null;
return b2r(queueStack.removeOne());
}
public synchronized yacyNewsRecord topInc() throws IOException, RowSpaceExceededException {
if (queueStack.isEmpty()) return null;
final yacyNewsRecord entry = pop();
if (entry != null) {
entry.incDistribution();
push(entry);
}
return entry;
}
public synchronized yacyNewsRecord get(final String id) {
yacyNewsRecord record;
final Iterator<yacyNewsRecord> i = records(true);
public synchronized yacyNewsDB.Record get(final String id) {
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> i = records(true);
while (i.hasNext()) {
record = i.next();
if ((record != null) && (record.id().equals(id))) return record;
@ -145,9 +135,9 @@ public class yacyNewsQueue {
return null;
}
public synchronized yacyNewsRecord remove(final String id) {
yacyNewsRecord record;
final Iterator<yacyNewsRecord> i = records(true);
public synchronized yacyNewsDB.Record remove(final String id) {
yacyNewsDB.Record record;
final Iterator<yacyNewsDB.Record> i = records(true);
while (i.hasNext()) {
record = i.next();
if ((record != null) && (record.id().equals(id))) {
@ -162,19 +152,19 @@ public class yacyNewsQueue {
return null;
}
yacyNewsRecord b2r(final Row.Entry b) throws IOException {
yacyNewsDB.Record b2r(final Row.Entry b) throws IOException {
if (b == null) return null;
final String id = b.getColString(0, null);
//Date touched = yacyCore.parseUniversalDate(new String(b[1]));
return newsDB.get(id);
}
private Row.Entry r2b(final yacyNewsRecord r, final boolean updateDB) throws IOException, RowSpaceExceededException {
private Row.Entry r2b(final yacyNewsDB.Record r, final boolean updateDB) throws IOException, RowSpaceExceededException {
if (r == null) return null;
if (updateDB) {
newsDB.put(r);
} else {
final yacyNewsRecord r1 = newsDB.get(r.id());
final yacyNewsDB.Record r1 = newsDB.get(r.id());
if (r1 == null) newsDB.put(r);
}
final Row.Entry b = queueStack.row().newEntry(new byte[][]{
@ -183,13 +173,13 @@ public class yacyNewsQueue {
return b;
}
public Iterator<yacyNewsRecord> records(final boolean up) {
public Iterator<yacyNewsDB.Record> records(final boolean up) {
// iterates yacyNewsRecord-type objects
if (queueStack == null) return new HashSet<yacyNewsRecord>().iterator();
if (queueStack == null) return new HashSet<yacyNewsDB.Record>().iterator();
return new newsIterator(up);
}
public class newsIterator implements Iterator<yacyNewsRecord> {
public class newsIterator implements Iterator<yacyNewsDB.Record> {
// iterates yacyNewsRecord-type objects
Iterator<Row.Entry> stackNodeIterator;
@ -207,7 +197,7 @@ public class yacyNewsQueue {
return stackNodeIterator.hasNext();
}
public yacyNewsRecord next() {
public yacyNewsDB.Record next() {
final Row.Entry row = stackNodeIterator.next();
try {
return b2r(row);

@ -1,230 +0,0 @@
// yacyNewsRecord.java
// -----------------------
// part of YaCy
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
//
// $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
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notice above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
package de.anomic.yacy;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.MapTools;
public class yacyNewsRecord {
public static final int maxNewsRecordLength = 512;
public static final int categoryStringLength = 8;
public static final int idLength = DateFormatter.PATTERN_SHORT_SECOND.length() + Word.commonHashLength;
private final String originator; // hash of originating peer
private final Date created; // Date when news was created by originator
private final Date received; // Date when news was received here at this peer
private final String category; // keyword that adresses possible actions
private int distributed; // counter that counts number of distributions of this news record
private final Map<String, String> attributes; // elemets of the news for a special category
public static final int attributesMaxLength = maxNewsRecordLength
- idLength
- categoryStringLength
- DateFormatter.PATTERN_SHORT_SECOND.length()
- 2;
public static final Row rowdef = new Row(
"String idx-" + idLength + " \"id = created + originator\"," +
"String cat-" + categoryStringLength + "," +
"String rec-" + DateFormatter.PATTERN_SHORT_SECOND.length() + "," +
"short dis-2 {b64e}," +
"String att-" + attributesMaxLength,
NaturalOrder.naturalOrder
);
public static yacyNewsRecord newRecord(final String newsString) {
try {
return new yacyNewsRecord(newsString);
} catch (final IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static yacyNewsRecord newRecord(final yacySeed mySeed, final String category, final Properties attributes) {
try {
final HashMap<String, String> m = new HashMap<String, String>();
final Iterator<Entry<Object, Object>> e = attributes.entrySet().iterator();
Map.Entry<Object, Object> entry;
while (e.hasNext()) {
entry = e.next();
m.put((String) entry.getKey(), (String) entry.getValue());
}
return new yacyNewsRecord(mySeed, category, m);
} catch (final IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static yacyNewsRecord newRecord(final yacySeed mySeed, final String category, final Map<String, String> attributes) {
try {
return new yacyNewsRecord(mySeed, category, attributes);
} catch (final IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public static yacyNewsRecord newRecord(final String id, final String category, final Date received, final int distributed, final Map<String, String> attributes) {
try {
return new yacyNewsRecord(id, category, received, distributed, attributes);
} catch (final IllegalArgumentException e) {
yacyCore.log.logWarning("rejected bad yacy news record: " + e.getMessage());
return null;
}
}
public yacyNewsRecord(final String newsString) {
this.attributes = MapTools.string2map(newsString, ",");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.category = (attributes.containsKey("cat")) ? attributes.get("cat") : "";
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
this.received = (attributes.containsKey("rec")) ? DateFormatter.parseShortSecond(attributes.get("rec"), DateFormatter.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? DateFormatter.parseShortSecond(attributes.get("cre"), DateFormatter.UTCDiffString()) : new Date();
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt(attributes.get("dis")) : 0;
this.originator = (attributes.containsKey("ori")) ? attributes.get("ori") : "";
removeStandards();
}
public yacyNewsRecord(final yacySeed mySeed, final String category, final Map<String, String> attributes) {
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = null;
this.created = new Date();
this.category = category;
this.distributed = 0;
this.originator = mySeed.hash;
removeStandards();
}
protected yacyNewsRecord(final String id, final String category, final Date received, final int distributed, final Map<String, String> attributes) {
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + categoryStringLength + ")");
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = received;
this.created = DateFormatter.parseShortSecond(id.substring(0, DateFormatter.PATTERN_SHORT_SECOND.length()), DateFormatter.UTCDiffString());
this.category = category;
this.distributed = distributed;
this.originator = id.substring(DateFormatter.PATTERN_SHORT_SECOND.length());
removeStandards();
}
private void removeStandards() {
attributes.remove("ori");
attributes.remove("cat");
attributes.remove("cre");
attributes.remove("rec");
attributes.remove("dis");
}
public String toString() {
// this creates the string that shall be distributed
// attention: this has no additional encoding
if (this.originator != null) attributes.put("ori", this.originator);
if (this.category != null) attributes.put("cat", this.category);
if (this.created != null) attributes.put("cre", DateFormatter.formatShortSecond(this.created));
if (this.received != null) attributes.put("rec", DateFormatter.formatShortSecond(this.received));
attributes.put("dis", Integer.toString(this.distributed));
final String theString = attributes.toString();
removeStandards();
return theString;
}
public String id() {
return DateFormatter.formatShortSecond(created) + originator;
}
public String originator() {
return originator;
}
public Date created() {
return created;
}
public Date received() {
return received;
}
public String category() {
return category;
}
public int distributed() {
return distributed;
}
public void incDistribution() {
distributed++;
}
public Map<String, String> attributes() {
return attributes;
}
public String attribute(final String key, final String dflt) {
final String s = attributes.get(key);
if ((s == null) || (s.length() == 0)) return dflt;
return s;
}
public static void main(final String[] args) {
System.out.println((newRecord(args[0])).toString());
}
}

@ -227,7 +227,7 @@ public class yacyPeerActions {
//System.out.println("### triggered news arrival from peer " + peer.getName() + ", news " + ((recordString == null) ? "empty" : "attached"));
if ((recordString == null) || (recordString.length() == 0)) return;
final String decodedString = de.anomic.tools.crypt.simpleDecode(recordString, "");
final yacyNewsRecord record = yacyNewsRecord.newRecord(decodedString);
final yacyNewsDB.Record record = new yacyNewsDB.Record(decodedString);
if (record != null) {
//System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
final String cre1 = MapTools.string2map(decodedString, ",").get("cre");

@ -124,6 +124,10 @@ public class GeonamesLocalization implements Localization {
Log.logException(e);
}
}
public int locations() {
return id2loc.size();
}
public Set<Location> find(String anyname, boolean locationexact) {
HashSet<Integer> r = new HashSet<Integer>();

@ -32,6 +32,12 @@ import java.util.Set;
*/
public interface Localization {
/**
* the number of locations that this localization stores
* @return the number of locations
*/
public int locations();
/**
* find a location by name
* @param anyname - a name of a location

@ -168,6 +168,10 @@ public class OpenGeoDBLocalization implements Localization {
s = s.substring(1, s.length() - 1);
return s;
}
public int locations() {
return id2loc.size();
}
/**
* check database tables against occurrences of this entity

@ -54,6 +54,14 @@ public class OverarchingLocalization implements Localization {
public void removeLocalization(String nickname) {
this.services.remove(nickname);
}
public int locations() {
int locations = 0;
for (Localization service: this.services.values()) {
locations += service.locations();
}
return locations;
}
/**
* find (a set of) locations

@ -99,6 +99,6 @@ public class ChunkIterator implements Iterator<byte[]> {
}
public void remove() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("no remove in ChunkIterator possible");
}
}

@ -814,7 +814,7 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
}
public void remove() {
throw new UnsupportedOperationException("no remove in row iterator");
ri.remove();
}
}
@ -871,7 +871,7 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
}
public void remove() {
throw new UnsupportedOperationException("no remove in TABLE");
throw new UnsupportedOperationException("no remove in Table.rowIterator");
}
}

Loading…
Cancel
Save