mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
added integration of osm maps for search
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6291 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
af3a696fc4
commit
2740d9dd79
|
@ -11,8 +11,8 @@ public class osm {
|
|||
public static ymageMatrix respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
|
||||
int zoom = 10;
|
||||
double lat = 47.968056d;
|
||||
double lon = 7.909167d;
|
||||
double lat = 50.11670d;
|
||||
double lon = 8.68333d;
|
||||
|
||||
if (post != null) {
|
||||
zoom = post.getInt("zoom", zoom);
|
||||
|
|
|
@ -127,6 +127,26 @@ document.getElementById("Enter").value = "search again";
|
|||
<p>Searching the web with this peer is disabled for unauthorized users. Please <a href="Status.html?login=">log in</a> as administrator to use the search function</p>
|
||||
#(/num-results)#
|
||||
|
||||
<!-- show openstreetmap tiles if geoinfo was found -->
|
||||
#(geoinfo)#
|
||||
::
|
||||
<div class="searchresults">
|
||||
<h4 class="linktitle">Location (click to enlarge)</h4>
|
||||
<p class="snippet">
|
||||
<table border="0"><tr><td>
|
||||
#{loc}#
|
||||
<div class="thumbcontainer">
|
||||
<a href="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" class="thumblink" onclick="return hs.expand(this)">
|
||||
<img src="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" width="192" height="192">
|
||||
</a>
|
||||
</div>
|
||||
#{/loc}#
|
||||
</tr></td></table>
|
||||
</p>
|
||||
<p class="urlinfo">Geographic information provided by <a href="http://opengeodb.hoppe-media.com">OpenGeoDB</a>, Map provided by <a href="http://www.openstreetmap.org">OpenStreetMap</a></p>
|
||||
</div>
|
||||
#(/geoinfo)#
|
||||
|
||||
<!-- the search results -->
|
||||
<script type="text/javascript">
|
||||
var progressbar = new Progressbar(#[results]#, document.getElementById("results"));
|
||||
|
|
|
@ -30,11 +30,14 @@
|
|||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
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.document.Condenser;
|
||||
import de.anomic.document.Word;
|
||||
import de.anomic.document.Document;
|
||||
|
@ -124,6 +127,7 @@ public class yacysearch {
|
|||
prop.put("num-results_totalcount", 0);
|
||||
prop.put("num-results_offset", 0);
|
||||
prop.put("num-results_itemsPerPage", 10);
|
||||
prop.put("geoinfo", "0");
|
||||
prop.put("rss_queryenc", "");
|
||||
|
||||
return prop;
|
||||
|
@ -482,7 +486,7 @@ public class yacysearch {
|
|||
meanMax = Integer.parseInt(post.get("meanCount"));
|
||||
}
|
||||
prop.put("meanCount", meanMax);
|
||||
if(meanMax > 0) {
|
||||
if (meanMax > 0) {
|
||||
DidYouMean didYouMean = new DidYouMean(sb.indexSegment.termIndex());
|
||||
Iterator<String> meanIt = didYouMean.getSuggestion(querystring).iterator();
|
||||
int meanCount = 0;
|
||||
|
@ -515,6 +519,21 @@ public class yacysearch {
|
|||
prop.put("didYouMean", 0);
|
||||
}
|
||||
|
||||
// find geographic info
|
||||
Set<Coordinates> coordinates = LibraryProvider.geoDB.find(originalquerystring);
|
||||
if (coordinates == null || coordinates.size() == 0) {
|
||||
prop.put("geoinfo", "0");
|
||||
} else {
|
||||
int i = 0;
|
||||
for (Coordinates c: coordinates) {
|
||||
prop.put("geoinfo_loc_" + i + "_lon", c.lon());
|
||||
prop.put("geoinfo_loc_" + i + "_lat", c.lat());
|
||||
i++;
|
||||
}
|
||||
prop.put("geoinfo_loc", i);
|
||||
prop.put("geoinfo", "1");
|
||||
}
|
||||
|
||||
// update the search tracker
|
||||
try {
|
||||
synchronized (trackerHandles) {
|
||||
|
|
66
source/de/anomic/data/Coordinates.java
Normal file
66
source/de/anomic/data/Coordinates.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Coordinates.java
|
||||
// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 04.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 Coordinates {
|
||||
|
||||
private double lon, lat;
|
||||
|
||||
public Coordinates(double lon, double lat) {
|
||||
this.lon = lon;
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double lon() {
|
||||
return this.lon;
|
||||
}
|
||||
|
||||
public double lat() {
|
||||
return this.lat;
|
||||
}
|
||||
|
||||
private static final double bits30 = new Double(1L << 30).doubleValue(); // this is about one billion (US)
|
||||
private static final double upscale = bits30 / 360.0;
|
||||
|
||||
private static final int coord2int(double coord) {
|
||||
return (int) ((coord + 180.0) * upscale);
|
||||
}
|
||||
|
||||
/**
|
||||
* compute the hash code of a coordinate
|
||||
* this produces identical hash codes for locations that are close to each other on longitude
|
||||
*/
|
||||
public int hashCode() {
|
||||
int lon1 = coord2int(this.lon) >> 15;
|
||||
int lat1 = coord2int(this.lat) >> 15;
|
||||
return (lon1 << 15) | lat1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + this.lon + "," + this.lat + "]";
|
||||
}
|
||||
}
|
|
@ -39,13 +39,13 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
||||
public class LibraryProvider {
|
||||
|
||||
private static final String path_to_source_dictionaries = "source";
|
||||
private static final String path_to_did_you_mean_dictionaries = "didyoumean";
|
||||
|
||||
public static DidYouMeanLibrary dymLib = new DidYouMeanLibrary(null);
|
||||
public static OpenGeoDB geoDB = new OpenGeoDB(null);
|
||||
public static File dictSource = null;
|
||||
public static File dictRoot = null;
|
||||
|
||||
|
@ -59,13 +59,20 @@ public class LibraryProvider {
|
|||
* @param pathToDICTIONARIES
|
||||
*/
|
||||
public static void initialize(File rootPath) {
|
||||
File dictSource = new File(rootPath, path_to_source_dictionaries);
|
||||
dictSource = new File(rootPath, path_to_source_dictionaries);
|
||||
if (!dictSource.exists()) dictSource.mkdirs();
|
||||
dictRoot = rootPath;
|
||||
|
||||
// initialize libraries
|
||||
integrateDeReWo();
|
||||
initDidYouMean();
|
||||
integrateOpenGeoDB();
|
||||
}
|
||||
|
||||
public static void integrateOpenGeoDB() {
|
||||
File ogdb = new File(dictSource, "opengeodb-0.2.5a-UTF8-sql.gz");
|
||||
if (!ogdb.exists()) return;
|
||||
geoDB = new OpenGeoDB(ogdb);
|
||||
}
|
||||
|
||||
public static void initDidYouMean() {
|
||||
|
|
183
source/de/anomic/data/OpenGeoDB.java
Normal file
183
source/de/anomic/data/OpenGeoDB.java
Normal file
|
@ -0,0 +1,183 @@
|
|||
// OpenGeoDB.java
|
||||
// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 04.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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* this class loads and parses database dumps from the OpenGeoDB project
|
||||
* files can be loaded from http://sourceforge.net/projects/opengeodb/files/
|
||||
* this class is used by the LibraryProvider, which expects input files inside
|
||||
* DATA\DICTIONARIES\source
|
||||
*
|
||||
* ATTENTION:
|
||||
* if this class is used, expect an extra memory usage of more than 100MB!
|
||||
*
|
||||
* This class will provide a super-fast access to the OpenGeoDB,
|
||||
* since all request are evaluated using data in the RAM.
|
||||
*/
|
||||
public class OpenGeoDB {
|
||||
|
||||
// use a collator to relax when distinguishing between lowercase und uppercase letters
|
||||
private static final Collator insensitiveCollator = Collator.getInstance(Locale.US);
|
||||
static {
|
||||
insensitiveCollator.setStrength(Collator.SECONDARY);
|
||||
insensitiveCollator.setDecomposition(Collator.NO_DECOMPOSITION);
|
||||
}
|
||||
|
||||
private HashMap<Integer, String> locTypeHash2locType;
|
||||
private HashMap<Integer, Coordinates> id2coord;
|
||||
private HashMap<Integer, Integer> id2locTypeHash;
|
||||
private TreeMap<String, List<Integer>> locationName2ids;
|
||||
private TreeMap<String, List<Integer>> kfz2ids;
|
||||
private HashMap<String, List<Integer>> predial2ids;
|
||||
private HashMap<String, Integer> zip2id;
|
||||
|
||||
public OpenGeoDB(final File file) {
|
||||
|
||||
this.locTypeHash2locType = new HashMap<Integer, String>();
|
||||
this.id2coord = new HashMap<Integer, Coordinates>();
|
||||
this.id2locTypeHash = new HashMap<Integer, Integer>();
|
||||
this.locationName2ids = new TreeMap<String, List<Integer>>(insensitiveCollator);
|
||||
this.kfz2ids = new TreeMap<String, List<Integer>>(insensitiveCollator);
|
||||
this.predial2ids = new HashMap<String, List<Integer>>();
|
||||
this.zip2id = new HashMap<String, Integer>();
|
||||
|
||||
if (file == null || !file.exists()) return;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
InputStream is = new FileInputStream(file);
|
||||
if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is);
|
||||
reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
|
||||
// read lines
|
||||
String[] v;
|
||||
Integer id;
|
||||
String h;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (!line.startsWith("INSERT INTO ")) continue;
|
||||
if (!line.endsWith(");")) continue;
|
||||
line = line.substring(12);
|
||||
//p = line.indexOf(' '); if (p < 0) continue;
|
||||
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])));
|
||||
}
|
||||
if (line.startsWith("geodb_textdata ")) {
|
||||
line = line.substring(15 + 7);
|
||||
v = line.split(",");
|
||||
if (v[1].equals("500100000")) { // Ortsname
|
||||
id = Integer.parseInt(v[0]);
|
||||
h = removeQuotes(v[2]);
|
||||
List<Integer> l = this.locationName2ids.get(h);
|
||||
if (l == null) l = new ArrayList<Integer>(1);
|
||||
l.add(id);
|
||||
this.locationName2ids.put(h, l);
|
||||
} else if (v[1].equals("500400000")) { // Vorwahl
|
||||
id = Integer.parseInt(v[0]);
|
||||
h = removeQuotes(v[2]);
|
||||
List<Integer> l = this.predial2ids.get(h);
|
||||
if (l == null) l = new ArrayList<Integer>(1);
|
||||
l.add(id);
|
||||
this.predial2ids.put(h, l);
|
||||
} else if (v[1].equals("400300000")) { // Ortstyp
|
||||
id = Integer.parseInt(v[0]);
|
||||
h = removeQuotes(v[2]);
|
||||
Integer hc = h.hashCode();
|
||||
String t = this.locTypeHash2locType.get(hc);
|
||||
if (t == null) this.locTypeHash2locType.put(hc, h);
|
||||
this.id2locTypeHash.put(id, hc);
|
||||
} else if (v[1].equals("500300000")) { // PLZ
|
||||
this.zip2id.put(removeQuotes(v[2]), Integer.parseInt(v[0]));
|
||||
} else if (v[1].equals("500500000")) { // KFZ-Kennzeichen
|
||||
id = Integer.parseInt(v[0]);
|
||||
h = removeQuotes(v[2]);
|
||||
List<Integer> l = this.kfz2ids.get(h);
|
||||
if (l == null) l = new ArrayList<Integer>(1);
|
||||
l.add(id);
|
||||
this.kfz2ids.put(h, l);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
reader.close();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) try { reader.close(); } catch (final Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String removeQuotes(String s) {
|
||||
if (s.charAt(0) != '\'') return s;
|
||||
if (s.charAt(s.length() - 1) != '\'') return s;
|
||||
s = s.substring(1, s.length() - 1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* check database tables against occurrences of this entity
|
||||
* the anyname - String may be one of:
|
||||
* - name of a town, villa, region etc
|
||||
* - zip code
|
||||
* - telephone prefix
|
||||
* - kfz sign
|
||||
* @param anyname
|
||||
* @return
|
||||
*/
|
||||
public HashSet<Coordinates> find(String anyname) {
|
||||
HashSet<Integer> r = new HashSet<Integer>();
|
||||
List<Integer> c;
|
||||
c = this.locationName2ids.get(anyname); if (c != null) r.addAll(c);
|
||||
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<Coordinates> a = new HashSet<Coordinates>();
|
||||
for (Integer e: r) {
|
||||
Coordinates w = this.id2coord.get(e);
|
||||
if (w != null) a.add(w);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
}
|
|
@ -43,9 +43,9 @@ public class gzip {
|
|||
|
||||
public static void gzipFile(final String inFile, final String outFile) {
|
||||
try {
|
||||
final InputStream fin = new FileInputStream(inFile);
|
||||
final OutputStream fout = new GZIPOutputStream(new FileOutputStream(outFile), 128);
|
||||
copy(fout, fin, 128);
|
||||
final InputStream fin = new BufferedInputStream(new FileInputStream(inFile));
|
||||
final OutputStream fout = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(outFile), 1024));
|
||||
copy(fout, fin, 1024);
|
||||
fin.close();
|
||||
fout.close();
|
||||
} catch (final FileNotFoundException e) {
|
||||
|
@ -57,11 +57,19 @@ public class gzip {
|
|||
}
|
||||
}
|
||||
|
||||
public static void gunzipFile(final String inFile, final String outFile) {
|
||||
public static File gunzipFile(File in) {
|
||||
assert in.getName().endsWith(".gz");
|
||||
String on = in.getName().substring(0, in.getName().length() - 3);
|
||||
File outf = new File(in.getParent(), on);
|
||||
gunzipFile(in, outf);
|
||||
return outf;
|
||||
}
|
||||
|
||||
public static void gunzipFile(final File inFile, final File outFile) {
|
||||
try {
|
||||
final InputStream fin = new GZIPInputStream(new FileInputStream(inFile));
|
||||
final OutputStream fout = new FileOutputStream(outFile);
|
||||
copy(fout, fin, 128);
|
||||
final InputStream fin = new GZIPInputStream(new BufferedInputStream(new FileInputStream(inFile)));
|
||||
final OutputStream fout = new BufferedOutputStream(new FileOutputStream(outFile));
|
||||
copy(fout, fin, 1024);
|
||||
fin.close();
|
||||
fout.close();
|
||||
} catch (final FileNotFoundException e) {
|
||||
|
@ -78,7 +86,7 @@ public class gzip {
|
|||
final InputStream fin = new ByteArrayInputStream(in.getBytes("UTF8"));
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length() / 3);
|
||||
final OutputStream fout = new GZIPOutputStream(baos, 128);
|
||||
copy(fout, fin, 128);
|
||||
copy(fout, fin, 1024);
|
||||
fin.close();
|
||||
fout.close();
|
||||
return baos.toByteArray();
|
||||
|
@ -92,7 +100,7 @@ public class gzip {
|
|||
public static String gunzipString(final byte[] in) throws IOException {
|
||||
final InputStream fin = new GZIPInputStream(new ByteArrayInputStream(in));
|
||||
final ByteArrayOutputStream fout = new ByteArrayOutputStream(in.length / 3);
|
||||
copy(fout, fin, 128);
|
||||
copy(fout, fin, 1024);
|
||||
fin.close();
|
||||
fout.close();
|
||||
return new String(fout.toByteArray(), "UTF-8");
|
||||
|
@ -178,7 +186,7 @@ public class gzip {
|
|||
} else {
|
||||
target = s[2];
|
||||
}
|
||||
gzip.gunzipFile((s[1]), target);
|
||||
gzip.gunzipFile(new File(s[1]), new File(target));
|
||||
System.exit(0);
|
||||
}
|
||||
if ((s.length < 1) || (s.length > 2)) {help(); System.exit(-1);}
|
||||
|
|
Loading…
Reference in New Issue
Block a user