mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
- corrected layout of map preview
- added caption to maps containing latitude and longitude information - prevented that maps occur on second search page - added location names to did-you-mean - some refactoring of did-you-mean - added equal and compareTo test to Coordinates class to make that work in set - fixed utf-8 support for library files - fixed a bug in images search icon view caption git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6294 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
4b83875abd
commit
eaddf2d464
|
@ -133,12 +133,16 @@ document.getElementById("Enter").value = "search again";
|
||||||
<div class="searchresults">
|
<div class="searchresults">
|
||||||
<h4 class="linktitle">
|
<h4 class="linktitle">
|
||||||
<img src="http://www.openstreetmap.org/favicon.ico" class="favicon" style="width:16px; height:16px;" alt="" />
|
<img src="http://www.openstreetmap.org/favicon.ico" class="favicon" style="width:16px; height:16px;" alt="" />
|
||||||
Location (click to enlarge)</h4>
|
Location -- click on map to enlarge</h4>
|
||||||
<p class="url">
|
<p class="url">
|
||||||
#{loc}#
|
#{loc}#
|
||||||
|
<div style="margin: 20px; width: 100px; float: left;">
|
||||||
<a href="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" class="thumblink" style="float:left;" onclick="return hs.expand(this)">
|
<a href="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" class="thumblink" style="float:left;" onclick="return hs.expand(this)">
|
||||||
<img src="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" width="768" height="768">
|
<img src="/osm.png?lon=#[lon]#&lat=#[lat]#&zoom=14" width="192" height="192">
|
||||||
</a>
|
</a>
|
||||||
|
<div class="highslide-caption">lat=#[lat]#, lon=#[lon]#</div>
|
||||||
|
<div class="TableCellDark">lat=#[lat]#,<br />lon=#[lon]#</div>
|
||||||
|
</div>
|
||||||
#{/loc}#
|
#{/loc}#
|
||||||
</p>
|
</p>
|
||||||
<p class="urlinfo" style="clear:left;">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>
|
<p class="urlinfo" style="clear:left;">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>
|
||||||
|
|
|
@ -521,14 +521,15 @@ public class yacysearch {
|
||||||
|
|
||||||
// find geographic info
|
// find geographic info
|
||||||
Set<Coordinates> coordinates = LibraryProvider.geoDB.find(originalquerystring);
|
Set<Coordinates> coordinates = LibraryProvider.geoDB.find(originalquerystring);
|
||||||
if (coordinates == null || coordinates.size() == 0) {
|
if (coordinates == null || coordinates.size() == 0 || offset > 0) {
|
||||||
prop.put("geoinfo", "0");
|
prop.put("geoinfo", "0");
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Coordinates c: coordinates) {
|
for (Coordinates c: coordinates) {
|
||||||
prop.put("geoinfo_loc_" + i + "_lon", c.lon());
|
prop.put("geoinfo_loc_" + i + "_lon", Math.round(c.lon() * 10000.0) / 10000.0);
|
||||||
prop.put("geoinfo_loc_" + i + "_lat", c.lat());
|
prop.put("geoinfo_loc_" + i + "_lat", Math.round(c.lat() * 10000.0) / 10000.0);
|
||||||
i++;
|
i++;
|
||||||
|
if (i >= 5) break;
|
||||||
}
|
}
|
||||||
prop.put("geoinfo_loc", i);
|
prop.put("geoinfo_loc", i);
|
||||||
prop.put("geoinfo", "1");
|
prop.put("geoinfo", "1");
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<a href="#[hrefCache]#" class="thumblink" onclick="return hs.expand(this)">
|
<a href="#[hrefCache]#" class="thumblink" onclick="return hs.expand(this)">
|
||||||
<img src="/ViewImage.png?maxwidth=96&maxheight=96&code=#[code]#" alt="#[name]#" />
|
<img src="/ViewImage.png?maxwidth=96&maxheight=96&code=#[code]#" alt="#[name]#" />
|
||||||
</a>
|
</a>
|
||||||
<div class="highslide-caption"><a href="#[href]#">#[name]#<br \><a href="#[source]#">#[sourcedom]#</a></a></div>
|
<div class="highslide-caption"><a href="#[href]#">#[name]#</a><br \><a href="#[source]#">#[sourcedom]#</a></div>
|
||||||
<div class="TableCellDark"><a href="#[href]#">#[name]#</a><br \>#[attr]#</div>
|
<div class="TableCellDark"><a href="#[href]#">#[name]#</a><br \>#[attr]#</div>
|
||||||
</div>
|
</div>
|
||||||
#{/items}#
|
#{/items}#
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
|
|
||||||
package de.anomic.data;
|
package de.anomic.data;
|
||||||
|
|
||||||
public class Coordinates {
|
public class Coordinates implements Comparable<Coordinates> {
|
||||||
|
|
||||||
|
private static final double tenmeter = 90.0 / 1.0e6;
|
||||||
|
|
||||||
private double lon, lat;
|
private double lon, lat;
|
||||||
|
|
||||||
|
@ -52,12 +54,37 @@ public class Coordinates {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compute the hash code of a coordinate
|
* compute the hash code of a coordinate
|
||||||
* this produces identical hash codes for locations that are close to each other on longitude
|
* this produces identical hash codes for locations that are close to each other
|
||||||
*/
|
*/
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int lon1 = coord2int(this.lon) >> 15;
|
int lon1 = coord2int(this.lon) >> 15;
|
||||||
int lat1 = coord2int(this.lat) >> 15;
|
int lat1 = coord2int(this.lat) >> 15;
|
||||||
return (lon1 << 15) | lat1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* equality test that is needed to use the class inside HashMap/HashSet
|
||||||
|
*/
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof Coordinates)) return false;
|
||||||
|
Coordinates oo = (Coordinates) o;
|
||||||
|
if (this.lon == oo.lon && this.lat == oo.lat) return true;
|
||||||
|
// we access fuzzy values that are considered as equal if they are close to each other
|
||||||
|
return Math.abs(this.lon - oo.lon) < tenmeter && Math.abs(this.lat - oo.lat) < tenmeter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -153,6 +153,14 @@ public class DidYouMean {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test(String s) throws InterruptedException {
|
||||||
|
Set<String> libr = LibraryProvider.dymLib.recommend(s);
|
||||||
|
libr.addAll(LibraryProvider.geoDB.recommend(s));
|
||||||
|
if (libr.size() != 0) createGen = false;
|
||||||
|
for (String t: libr) guessLib.put(t);
|
||||||
|
if (createGen) guessGen.put(s);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DidYouMean's producer thread that changes one letter (e.g. bat/cat) for a given term
|
* DidYouMean's producer thread that changes one letter (e.g. bat/cat) for a given term
|
||||||
* based on the given alphabet and puts it on the blocking queue, to be 'consumed' by a consumer thread.<p/>
|
* based on the given alphabet and puts it on the blocking queue, to be 'consumed' by a consumer thread.<p/>
|
||||||
|
@ -161,15 +169,9 @@ public class DidYouMean {
|
||||||
public class ChangingOneLetter extends Thread {
|
public class ChangingOneLetter extends Thread {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
String s;
|
|
||||||
Set<String> libr;
|
|
||||||
for (int i = 0; i < wordLen; i++) try {
|
for (int i = 0; i < wordLen; i++) try {
|
||||||
for (char c: alphabet) {
|
for (char c: alphabet) {
|
||||||
s = word.substring(0, i) + c + word.substring(i + 1);
|
test(word.substring(0, i) + c + word.substring(i + 1));
|
||||||
libr = LibraryProvider.dymLib.recommend(s);
|
|
||||||
if (libr.size() != 0) createGen = false;
|
|
||||||
for (String t: libr) guessLib.put(t);
|
|
||||||
if (createGen) guessGen.put(s);
|
|
||||||
if (System.currentTimeMillis() > timeLimit) return;
|
if (System.currentTimeMillis() > timeLimit) return;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
|
@ -184,14 +186,8 @@ public class DidYouMean {
|
||||||
protected class DeletingOneLetter extends Thread {
|
protected class DeletingOneLetter extends Thread {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
String s;
|
|
||||||
Set<String> libr;
|
|
||||||
for (int i = 0; i < wordLen; i++) try {
|
for (int i = 0; i < wordLen; i++) try {
|
||||||
s = word.substring(0, i) + word.substring(i+1);
|
test(word.substring(0, i) + word.substring(i+1));
|
||||||
libr = LibraryProvider.dymLib.recommend(s);
|
|
||||||
if (libr.size() != 0) createGen = false;
|
|
||||||
for (String t: libr) guessLib.put(t);
|
|
||||||
if (createGen) guessGen.put(s);
|
|
||||||
if (System.currentTimeMillis() > timeLimit) return;
|
if (System.currentTimeMillis() > timeLimit) return;
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
@ -205,15 +201,9 @@ public class DidYouMean {
|
||||||
protected class AddingOneLetter extends Thread {
|
protected class AddingOneLetter extends Thread {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
String s;
|
|
||||||
Set<String> libr;
|
|
||||||
for (int i = 0; i <= wordLen; i++) try {
|
for (int i = 0; i <= wordLen; i++) try {
|
||||||
for (char c: alphabet) {
|
for (char c: alphabet) {
|
||||||
s = word.substring(0, i) + c + word.substring(i);
|
test(word.substring(0, i) + c + word.substring(i));
|
||||||
libr = LibraryProvider.dymLib.recommend(s);
|
|
||||||
if (libr.size() != 0) createGen = false;
|
|
||||||
for (String t: libr) guessLib.put(t);
|
|
||||||
if (createGen) guessGen.put(s);
|
|
||||||
if (System.currentTimeMillis() > timeLimit) return;
|
if (System.currentTimeMillis() > timeLimit) return;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
|
@ -228,14 +218,8 @@ public class DidYouMean {
|
||||||
protected class ReversingTwoConsecutiveLetters extends Thread {
|
protected class ReversingTwoConsecutiveLetters extends Thread {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
String s;
|
|
||||||
Set<String> libr;
|
|
||||||
for (int i = 0; i < wordLen - 1; i++) try {
|
for (int i = 0; i < wordLen - 1; i++) try {
|
||||||
s = word.substring(0, i) + word.charAt(i + 1) + word.charAt(i) + word.substring(i +2);
|
test(word.substring(0, i) + word.charAt(i + 1) + word.charAt(i) + word.substring(i +2));
|
||||||
libr = LibraryProvider.dymLib.recommend(s);
|
|
||||||
if (libr.size() != 0) createGen = false;
|
|
||||||
for (String t: libr) guessLib.put(t);
|
|
||||||
if (createGen) guessGen.put(s);
|
|
||||||
if (System.currentTimeMillis() > timeLimit) return;
|
if (System.currentTimeMillis() > timeLimit) return;
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,15 @@ package de.anomic.data;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* provide a completion library for the did-you-mean class
|
* provide a completion library for the did-you-mean class
|
||||||
|
@ -68,14 +70,16 @@ public class DidYouMeanLibrary {
|
||||||
for (String f: files) {
|
for (String f: files) {
|
||||||
if (f.endsWith(".words")) try {
|
if (f.endsWith(".words")) try {
|
||||||
importFile(new File(dictionaryPath, f));
|
importFile(new File(dictionaryPath, f));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importFile(File f) throws FileNotFoundException {
|
private void importFile(File f) throws IOException {
|
||||||
BufferedReader r = new BufferedReader(new FileReader(f));
|
InputStream is = new FileInputStream(f);
|
||||||
|
if (f.getName().endsWith(".gz")) is = new GZIPInputStream(is);
|
||||||
|
BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
String l;
|
String l;
|
||||||
try {
|
try {
|
||||||
while ((l = r.readLine()) != null) {
|
while ((l = r.readLine()) != null) {
|
||||||
|
|
|
@ -70,9 +70,21 @@ public class LibraryProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void integrateOpenGeoDB() {
|
public static void integrateOpenGeoDB() {
|
||||||
File ogdb = new File(dictSource, "opengeodb-0.2.5a-UTF8-sql.gz"); // may also be named opengeodb-02513_2007-10-02.sql.gz
|
File ogdb = new File(dictSource, "opengeodb-0.2.5a-UTF8-sql.gz");
|
||||||
if (!ogdb.exists()) return;
|
if (ogdb.exists()) {
|
||||||
geoDB = new OpenGeoDB(ogdb);
|
geoDB = new OpenGeoDB(ogdb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ogdb = new File(dictSource, "opengeodb-02513_2007-10-02.sql.gz");
|
||||||
|
if (ogdb.exists()) {
|
||||||
|
geoDB = new OpenGeoDB(ogdb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ogdb = new File(dictSource, "opengeodb-02513_2007-10-02.sql");
|
||||||
|
if (ogdb.exists()) {
|
||||||
|
geoDB = new OpenGeoDB(ogdb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initDidYouMean() {
|
public static void initDidYouMean() {
|
||||||
|
@ -140,7 +152,7 @@ public class LibraryProvider {
|
||||||
final ArrayList<String> list = new ArrayList<String>();
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
// read until text starts
|
// read until text starts
|
||||||
|
|
|
@ -38,6 +38,9 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.SortedSet;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
@ -85,7 +88,7 @@ public class OpenGeoDB {
|
||||||
try {
|
try {
|
||||||
InputStream is = new FileInputStream(file);
|
InputStream is = new FileInputStream(file);
|
||||||
if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is);
|
if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is);
|
||||||
reader = new BufferedReader(new InputStreamReader(is));
|
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
// read lines
|
// read lines
|
||||||
|
@ -180,4 +183,18 @@ public class OpenGeoDB {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read the dictionary and construct a set of recommendations to a given string
|
||||||
|
* @param s input value that is used to match recommendations
|
||||||
|
* @return a set that contains all words that start or end with the input value
|
||||||
|
*/
|
||||||
|
public Set<String> recommend(String s) {
|
||||||
|
Set<String> a = new HashSet<String>();
|
||||||
|
s = s.trim().toLowerCase();
|
||||||
|
SortedMap<String, List<Integer>> t = this.locationName2ids.tailMap(s);
|
||||||
|
for (String r: t.keySet()) {
|
||||||
|
if (r.startsWith(s)) a.add(r); else break;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import de.anomic.crawler.CrawlProfile;
|
||||||
import de.anomic.crawler.retrieval.Response;
|
import de.anomic.crawler.retrieval.Response;
|
||||||
import de.anomic.http.client.Cache;
|
import de.anomic.http.client.Cache;
|
||||||
import de.anomic.search.Switchboard;
|
import de.anomic.search.Switchboard;
|
||||||
|
@ -77,13 +78,13 @@ public class ymageOSM {
|
||||||
} catch (final MalformedURLException e) {
|
} catch (final MalformedURLException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
System.out.println("*** DEBUG: fetching OSM tile: " + tileURL.toNormalform(true, true));
|
//System.out.println("*** DEBUG: fetching OSM tile: " + tileURL.toNormalform(true, true));
|
||||||
InputStream tileStream = Cache.getContentStream(tileURL);
|
InputStream tileStream = Cache.getContentStream(tileURL);
|
||||||
if (tileStream == null) {
|
if (tileStream == null) {
|
||||||
// download resource using the crawler and keep resource in memory if possible
|
// download resource using the crawler and keep resource in memory if possible
|
||||||
Response entry = null;
|
Response entry = null;
|
||||||
try {
|
try {
|
||||||
entry = Switchboard.getSwitchboard().loader.load(tileURL, false, false);
|
entry = Switchboard.getSwitchboard().loader.load(tileURL, false, false, CrawlProfile.CACHE_STRATEGY_IFEXIST);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.logWarning("yamyOSM", "cannot load: " + e.getMessage());
|
Log.logWarning("yamyOSM", "cannot load: " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user