Skip to content

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

- show up to 10 locations (maps) after search (instead of a max of 5) - order locations by (primary) population and (secondary) longitude (reverse ordering, both) - added population from GeoNames, OpenGeoDB does not have that information - changed default viewpoint of map to (30,15); shows more land and europe in the center

orbiter98c1d6541595
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 78ed31933..b4b54b578 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -30,7 +30,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.Set;
import java.util.TreeSet;
import net.yacy.document.Condenser;
@@ -559,7 +558,7 @@ public class yacysearch {
}
// find geographic info
- Set<Location> coordinates = LibraryProvider.geoLoc.find(originalquerystring, false);
+ TreeSet<Location> coordinates = LibraryProvider.geoLoc.find(originalquerystring, false);
if (coordinates == null || coordinates.isEmpty() || offset > 0) {
prop.put("geoinfo", "0");
} else {
@@ -569,7 +568,7 @@ public class yacysearch {
prop.put("geoinfo_loc_" + i + "_lat", Math.round(c.lat() * 10000.0) / 10000.0);
prop.put("geoinfo_loc_" + i + "_name", c.getName());
i++;
- if (i >= 5) break;
+ if (i >= 10) break;
}
prop.put("geoinfo_loc", i);
prop.put("geoinfo", "1");
diff --git a/htroot/yacysearch_location.html b/htroot/yacysearch_location.html
index 1e9e3a33d..fda7ec6b7 100644
--- a/htroot/yacysearch_location.html
+++ b/htroot/yacysearch_location.html
@@ -36,7 +36,7 @@
map.addLayer(layerMaplint);
map.addLayer(layerWMS);
map.addControl(new OpenLayers.Control.LayerSwitcher());
- map.setCenter(new OpenLayers.LonLat(0,0) // Center of the map
+ map.setCenter(new OpenLayers.LonLat(15,30) // Center of the map
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
diff --git a/source/net/yacy/document/geolocalization/Coordinates.java b/source/net/yacy/document/geolocalization/Coordinates.java
index e7cb7a2ee..e4643cfbb 100644
--- a/source/net/yacy/document/geolocalization/Coordinates.java
+++ b/source/net/yacy/document/geolocalization/Coordinates.java
@@ -22,9 +22,7 @@
package net.yacy.document.geolocalization;
-import java.util.Comparator;
-
-public class Coordinates implements Comparable<Coordinates>, Comparator<Coordinates> {
+public class Coordinates {
private static final double tenmeter = 90.0 / 1.0e6;
@@ -47,7 +45,7 @@ public class Coordinates implements Comparable<Coordinates>, Comparator<Coordina
private static final double upscale = bits30 / 360.0;
private static final int coord2int(double coord) {
- return (int) ((coord + 180.0) * upscale);
+ return (int) ((180.0 - coord) * upscale);
}
/**
@@ -55,27 +53,7 @@ public class Coordinates implements Comparable<Coordinates>, Comparator<Coordina
* this produces identical hash codes for locations that are close to each other
*/
public int hashCode() {
- int lon1 = coord2int(this.lon) >> 15;
- int lat1 = coord2int(this.lat) >> 15;
- int h = (lon1 << 15) + lat1;
- //System.out.println("lon=" + this.lon + ", lat=" + this.lat + ", hash=" + h);
- return h;
- }
-
- /**
- * comparator that is needed to use the class inside TreeMap/TreeSet
- */
- public int compareTo(Coordinates o) {
- if (this.equals(o)) return 0;
- int s = this.hashCode();
- int t = o.hashCode();
- if (s > t) return 1;
- if (s < t) return -1;
- return 0;
- }
-
- public int compare(Coordinates o1, Coordinates o2) {
- return o1.compareTo(o2);
+ return coord2int(this.lon) + (coord2int(this.lat) >> 15);
}
/**
diff --git a/source/net/yacy/document/geolocalization/GeonamesLocalization.java b/source/net/yacy/document/geolocalization/GeonamesLocalization.java
index 887046caf..ec4037553 100644
--- a/source/net/yacy/document/geolocalization/GeonamesLocalization.java
+++ b/source/net/yacy/document/geolocalization/GeonamesLocalization.java
@@ -37,6 +37,7 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -112,6 +113,7 @@ public class GeonamesLocalization implements Localization {
locnames.add(fields[2]);
for (String s: fields[3].split(",")) locnames.add(s);
Location c = new Location(Double.parseDouble(fields[5]), Double.parseDouble(fields[4]), fields[1]);
+ c.setPopulation((int) Long.parseLong(fields[14]));
this.id2loc.put(id, c);
for (String name: locnames) {
List<Integer> locs = this.name2ids.get(name);
@@ -129,8 +131,8 @@ public class GeonamesLocalization implements Localization {
return id2loc.size();
}
- public Set<Location> find(String anyname, boolean locationexact) {
- HashSet<Integer> r = new HashSet<Integer>();
+ public TreeSet<Location> find(String anyname, boolean locationexact) {
+ Set<Integer> r = new HashSet<Integer>();
List<Integer> c;
if (locationexact) {
c = this.name2ids.get(anyname); if (c != null) r.addAll(c);
@@ -140,7 +142,7 @@ public class GeonamesLocalization implements Localization {
if (e.getKey().toLowerCase().startsWith(anyname.toLowerCase())) r.addAll(e.getValue()); else break;
}
}
- HashSet<Location> a = new HashSet<Location>();
+ TreeSet<Location> a = new TreeSet<Location>();
for (Integer e: r) {
Location w = this.id2loc.get(e);
if (w != null) a.add(w);
diff --git a/source/net/yacy/document/geolocalization/Localization.java b/source/net/yacy/document/geolocalization/Localization.java
index eaccacf81..49864befc 100644
--- a/source/net/yacy/document/geolocalization/Localization.java
+++ b/source/net/yacy/document/geolocalization/Localization.java
@@ -24,6 +24,7 @@
package net.yacy.document.geolocalization;
import java.util.Set;
+import java.util.TreeSet;
/**
* localization interface
@@ -42,9 +43,9 @@ public interface Localization {
* find a location by name
* @param anyname - a name of a location
* @param locationexact - if true, then only exact matched with the location are returned. if false also partially matching names
- * @return a set of locations
+ * @return a set of locations, ordered by population (if this information is given)
*/
- public Set<Location> find(String anyname, boolean locationexact);
+ public TreeSet<Location> find(String anyname, boolean locationexact);
/**
* recommend a set of names according to a given name
diff --git a/source/net/yacy/document/geolocalization/Location.java b/source/net/yacy/document/geolocalization/Location.java
index 86b15146c..bcab45f3e 100644
--- a/source/net/yacy/document/geolocalization/Location.java
+++ b/source/net/yacy/document/geolocalization/Location.java
@@ -22,14 +22,18 @@
package net.yacy.document.geolocalization;
+import java.util.Comparator;
-public class Location extends Coordinates {
+
+public class Location extends Coordinates implements Comparable<Location>, Comparator<Location> {
private String name;
+ private int population;
public Location(double lon, double lat) {
super(lon, lat);
this.name = null;
+ this.population = 0;
}
public Location(double lon, double lat, String name) {
@@ -45,10 +49,42 @@ public class Location extends Coordinates {
return this.name;
}
+ public void setPopulation(int population) {
+ this.population = population;
+ }
+
+ public int getPopulation() {
+ return this.population;
+ }
+
public boolean equals(Object loc) {
if (!(loc instanceof Location)) return false;
if (this.name == null || ((Location) loc).name == null) return super.equals(loc);
return super.equals(loc) && this.name.toLowerCase().equals(((Location) loc).name.toLowerCase());
}
+ /**
+ * comparator that is needed to use the object inside TreeMap/TreeSet
+ * a Location is smaller than another if it has a _greater_ population
+ * this order is used to get sorted lists of locations where the first elements
+ * have the greatest population
+ */
+ public int compareTo(Location o) {
+ if (this.equals(o)) return 0;
+ long s = (ph(this.getPopulation()) << 30) + this.hashCode();
+ long t = (ph(o.getPopulation()) << 30) + o.hashCode();
+ if (s > t) return -1;
+ if (s < t) return 1;
+ return 0;
+ }
+
+ private long ph(int population) {
+ if (population > 10000) population -= 10000;
+ return (long) population;
+ }
+
+ public int compare(Location o1, Location o2) {
+ return o1.compareTo(o2);
+ }
+
}
diff --git a/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java b/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java
index 5568c3a35..c63a7d6e7 100644
--- a/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java
+++ b/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java
@@ -38,6 +38,7 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.zip.GZIPInputStream;
import net.yacy.kelondro.logging.Log;
@@ -183,7 +184,7 @@ public class OpenGeoDBLocalization implements Localization {
* @param anyname
* @return
*/
- public HashSet<Location> find(String anyname, boolean locationexact) {
+ public TreeSet<Location> find(String anyname, boolean locationexact) {
HashSet<Integer> r = new HashSet<Integer>();
List<Integer> c;
if (locationexact) {
@@ -197,7 +198,7 @@ public class OpenGeoDBLocalization implements Localization {
c = this.predial2ids.get(anyname); if (c != null) r.addAll(c);
Integer i = this.zip2id.get(anyname); if (i != null) r.add(i);
}
- HashSet<Location> a = new HashSet<Location>();
+ TreeSet<Location> a = new TreeSet<Location>();
for (Integer e: r) {
Location w = this.id2loc.get(e);
if (w != null) a.add(w);
diff --git a/source/net/yacy/document/geolocalization/OverarchingLocalization.java b/source/net/yacy/document/geolocalization/OverarchingLocalization.java
index 060b09d5a..1d53c992e 100644
--- a/source/net/yacy/document/geolocalization/OverarchingLocalization.java
+++ b/source/net/yacy/document/geolocalization/OverarchingLocalization.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
public class OverarchingLocalization implements Localization {
@@ -66,8 +67,8 @@ public class OverarchingLocalization implements Localization {
/**
* find (a set of) locations
*/
- public Set<Location> find(String anyname, boolean locationexact) {
- Set<Location> locations = new HashSet<Location>();
+ public TreeSet<Location> find(String anyname, boolean locationexact) {
+ TreeSet<Location> locations = new TreeSet<Location>();
for (Localization service: this.services.values()) {
locations.addAll(service.find(anyname, locationexact));
}