From 789c6b26ce0698bcad19f93f0acfe3e30017c6b6 Mon Sep 17 00:00:00 2001
From: orbiter
Date: Tue, 11 May 2010 12:58:05 +0000
Subject: [PATCH] added a location search service: using the following
servlet/example:
http://localhost:8080/yacysearch_location.kml?query=berlin&maximumTime=2000&maximumRecords=100
This will open any application that can consume kml data (which will probably be google earth) on your computer and displays the search result as positions on a map
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6865 6c8d7289-2bf4-0310-a012-ef5d649a1542
---
htroot/yacysearch.java | 2 +-
htroot/yacysearch_location.java | 98 +++++++++++++++++++
htroot/yacysearch_location.kml | 20 ++++
htroot/yacysearch_location.xml | 20 ++++
htroot/yacysearchitem.java | 5 +-
htroot/yacysearchitem.xml | 6 +-
source/de/anomic/search/Switchboard.java | 20 ----
source/de/anomic/yacy/yacyClient.java | 3 +-
.../net/yacy/document/content/RSSMessage.java | 4 +
.../document/geolocalization/OpenGeoDB.java | 22 +++--
.../net/yacy/kelondro/util/DateFormatter.java | 13 ++-
11 files changed, 174 insertions(+), 39 deletions(-)
create mode 100644 htroot/yacysearch_location.java
create mode 100644 htroot/yacysearch_location.kml
create mode 100644 htroot/yacysearch_location.xml
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 900e771a3..59b2393e8 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -560,7 +560,7 @@ public class yacysearch {
}
// find geographic info
- Set coordinates = LibraryProvider.geoDB.find(originalquerystring, false);
+ Set coordinates = LibraryProvider.geoDB.find(originalquerystring, true, false, true, true, true);
if (coordinates == null || coordinates.isEmpty() || offset > 0) {
prop.put("geoinfo", "0");
} else {
diff --git a/htroot/yacysearch_location.java b/htroot/yacysearch_location.java
new file mode 100644
index 000000000..2dbb4358c
--- /dev/null
+++ b/htroot/yacysearch_location.java
@@ -0,0 +1,98 @@
+// yacysearch_location.java
+// -----------------------
+// (C) 2010 by Michael Peter Christen; mc@yacy.net
+// first published 09.05.2010 in Frankfurt, Germany on http://yacy.net
+//
+// 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
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+
+import net.yacy.document.content.RSSMessage;
+import net.yacy.document.geolocalization.Location;
+import de.anomic.data.LibraryProvider;
+import de.anomic.http.server.HeaderFramework;
+import de.anomic.http.server.RequestHeader;
+import de.anomic.server.serverObjects;
+import de.anomic.server.serverSwitch;
+import de.anomic.yacy.yacyClient;
+
+public class yacysearch_location {
+
+ public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ //final Switchboard sb = (Switchboard) env;
+ final serverObjects prop = new serverObjects();
+
+ prop.put("kml", 0);
+ if (post == null) return prop;
+
+ if (header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("kml") || header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("xml")) {
+ // generate a kml output page
+ prop.put("kml", 1);
+ String query = post.get("query", "");
+ 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 results = yacyClient.search(null, query, false, false, maximumTime, Integer.MAX_VALUE);
+
+ // take the results and compute some locations
+ RSSMessage message;
+ int placemarkCounter = 0;
+ try {
+ loop: while ((message = results.take()) != RSSMessage.POISON) {
+ // find all associated locations
+ Set locations = new HashSet();
+ String words = message.getTitle() + " " + message.getCopyright() + " " + message.getAuthor();
+ String subject = "";
+ for (String s: message.getSubject()) subject += " " + s;
+ words += subject;
+ for (String word: words.split(" ")) if (word.length() >= 3) locations.addAll(LibraryProvider.geoDB.find(word, true, true, false, false, false));
+
+ if (locations.size() > 0) {
+ String locnames = "";
+ for (Location location: locations) locnames += ", " + location.getName();
+ locnames = locnames.substring(2);
+ // write for all locations a point to this message
+ prop.put("kml_placemark_" + placemarkCounter + "_location", locnames);
+ prop.put("kml_placemark_" + placemarkCounter + "_name", message.getTitle());
+ prop.put("kml_placemark_" + placemarkCounter + "_author", message.getAuthor());
+ prop.put("kml_placemark_" + placemarkCounter + "_copyright", message.getCopyright());
+ prop.put("kml_placemark_" + placemarkCounter + "_subject", subject.trim());
+ prop.put("kml_placemark_" + placemarkCounter + "_description", message.getDescription());
+ prop.put("kml_placemark_" + placemarkCounter + "_date", message.getPubDate());
+ prop.put("kml_placemark_" + placemarkCounter + "_url", message.getLink());
+ int pc = 0;
+ for (Location location: locations) {
+ prop.put("kml_placemark_" + placemarkCounter + "_point_" + pc + "_name", location.getName());
+ prop.put("kml_placemark_" + placemarkCounter + "_point_" + pc + "_lon", location.lon());
+ prop.put("kml_placemark_" + placemarkCounter + "_point_" + pc + "_lat", location.lat());
+ pc++;
+ }
+ prop.put("kml_placemark_" + placemarkCounter + "_point", pc);
+ placemarkCounter++;
+ if (placemarkCounter >= maximumRecords) break loop;
+ }
+ }
+ prop.put("kml_placemark", placemarkCounter);
+ } catch (InterruptedException e) {}
+ }
+ // return rewrite properties
+ return prop;
+ }
+
+}
diff --git a/htroot/yacysearch_location.kml b/htroot/yacysearch_location.kml
new file mode 100644
index 000000000..a8272e530
--- /dev/null
+++ b/htroot/yacysearch_location.kml
@@ -0,0 +1,20 @@
+#(kml)#::
+
+
+ #{placemark}#
+
+ #[name]#
+ Location: #[location]#