From a58d9cae7d3dac235d55d16c9ee27b10265d9cb1 Mon Sep 17 00:00:00 2001
From: orbiter
Date: Tue, 8 Sep 2009 10:18:03 +0000
Subject: [PATCH] - show location name in geolocalization search result - added
link from location icon to openstreetmap browser with coordinates
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6305 6c8d7289-2bf4-0310-a012-ef5d649a1542
---
htroot/yacysearch.html | 4 +--
htroot/yacysearch.java | 7 ++--
source/de/anomic/data/Location.java | 51 ++++++++++++++++++++++++++++
source/de/anomic/data/OpenGeoDB.java | 14 ++++----
4 files changed, 65 insertions(+), 11 deletions(-)
create mode 100644 source/de/anomic/data/Location.java
diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html
index 1bd8024c6..9159be117 100644
--- a/htroot/yacysearch.html
+++ b/htroot/yacysearch.html
@@ -140,8 +140,8 @@ document.getElementById("Enter").value = "search again";
- lat=#[lat]#, lon=#[lon]#
- lat=#[lat]#,
lon=#[lon]#
+
+
#{/loc}#
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 98f9e2cac..24d2deeb9 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -35,9 +35,9 @@ import java.util.TreeSet;
import de.anomic.content.RSSMessage;
import de.anomic.crawler.retrieval.LoaderDispatcher;
-import de.anomic.data.Coordinates;
import de.anomic.data.DidYouMean;
import de.anomic.data.LibraryProvider;
+import de.anomic.data.Location;
import de.anomic.document.Condenser;
import de.anomic.document.Word;
import de.anomic.document.Document;
@@ -520,14 +520,15 @@ public class yacysearch {
}
// find geographic info
- Set coordinates = LibraryProvider.geoDB.find(originalquerystring);
+ Set coordinates = LibraryProvider.geoDB.find(originalquerystring);
if (coordinates == null || coordinates.size() == 0 || offset > 0) {
prop.put("geoinfo", "0");
} else {
int i = 0;
- for (Coordinates c: coordinates) {
+ for (Location c: coordinates) {
prop.put("geoinfo_loc_" + i + "_lon", Math.round(c.lon() * 10000.0) / 10000.0);
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;
}
diff --git a/source/de/anomic/data/Location.java b/source/de/anomic/data/Location.java
new file mode 100644
index 000000000..5fcc61fd8
--- /dev/null
+++ b/source/de/anomic/data/Location.java
@@ -0,0 +1,51 @@
+// Coordinates.java
+// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
+// first published 08.10.2009 on http://yacy.net
+//
+// This is a part of YaCy
+//
+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
+// $LastChangedRevision: 1986 $
+// $LastChangedBy: orbiter $
+//
+// LICENSE
+//
+// 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
+
+package de.anomic.data;
+
+public class Location extends Coordinates {
+
+ private String name;
+
+ public Location(double lon, double lat) {
+ super(lon, lat);
+ this.name = null;
+ }
+
+ public Location(double lon, double lat, String name) {
+ super(lon, lat);
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+}
diff --git a/source/de/anomic/data/OpenGeoDB.java b/source/de/anomic/data/OpenGeoDB.java
index 4405badda..92d764a46 100644
--- a/source/de/anomic/data/OpenGeoDB.java
+++ b/source/de/anomic/data/OpenGeoDB.java
@@ -66,7 +66,7 @@ public class OpenGeoDB {
}
private HashMap locTypeHash2locType;
- private HashMap id2coord;
+ private HashMap id2loc;
private HashMap id2locTypeHash;
private TreeMap> locationName2ids;
private TreeMap> kfz2ids;
@@ -76,7 +76,7 @@ public class OpenGeoDB {
public OpenGeoDB(final File file) {
this.locTypeHash2locType = new HashMap();
- this.id2coord = new HashMap();
+ this.id2loc = new HashMap();
this.id2locTypeHash = new HashMap();
this.locationName2ids = new TreeMap>(insensitiveCollator);
this.kfz2ids = new TreeMap>(insensitiveCollator);
@@ -104,7 +104,7 @@ public class OpenGeoDB {
if (line.startsWith("geodb_coordinates ")) {
line = line.substring(18 + 7);v = line.split(",");
v = line.split(",");
- id2coord.put(Integer.parseInt(v[0]), new Coordinates(Double.parseDouble(v[2]), Double.parseDouble(v[3])));
+ id2loc.put(Integer.parseInt(v[0]), new Location(Double.parseDouble(v[2]), Double.parseDouble(v[3])));
}
if (line.startsWith("geodb_textdata ")) {
line = line.substring(15 + 7);
@@ -116,6 +116,8 @@ public class OpenGeoDB {
if (l == null) l = new ArrayList(1);
l.add(id);
this.locationName2ids.put(h, l);
+ Location loc = this.id2loc.get(id);
+ if (loc != null) loc.setName(h);
} else if (v[1].equals("500400000")) { // Vorwahl
id = Integer.parseInt(v[0]);
h = removeQuotes(v[2]);
@@ -168,7 +170,7 @@ public class OpenGeoDB {
* @param anyname
* @return
*/
- public HashSet find(String anyname) {
+ public HashSet find(String anyname) {
HashSet r = new HashSet();
SortedMap> cities = this.locationName2ids.tailMap(anyname);
for (Map.Entry> e: cities.entrySet()) {
@@ -178,9 +180,9 @@ public class OpenGeoDB {
c = this.kfz2ids.get(anyname); if (c != null) r.addAll(c);
c = this.predial2ids.get(anyname); if (c != null) r.addAll(c);
Integer i = this.zip2id.get(anyname); if (i != null) r.add(i);
- HashSet a = new HashSet();
+ HashSet a = new HashSet();
for (Integer e: r) {
- Coordinates w = this.id2coord.get(e);
+ Location w = this.id2loc.get(e);
if (w != null) a.add(w);
}
return a;