Skip to content

Commit

Permalink
ehanced location search:
Browse files Browse the repository at this point in the history
- search request are now made using a map boundary
- search results are only computed for the map boundary
- the number of results is adopted to the results in the visible range
- added a double-buffering for the search result markers
- added a search query option for the search results:
/radius/<lat>/<lon>/<radius>
  • Loading branch information
Orbiter committed May 31, 2012
1 parent 434af40 commit 9b4c699
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 92 deletions.
4 changes: 2 additions & 2 deletions htroot/yacy/search.java
Expand Up @@ -255,7 +255,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
indexSegment,
rankingProfile,
header.get(RequestHeader.USER_AGENT, ""),
false
false, 0.0d, 0.0d, 0.0d
);
Network.log.logInfo("INIT HASH SEARCH (abstracts only): " + QueryParams.anonymizedQueryHashes(theQuery.queryHashes) + " - " + theQuery.itemsPerPage() + " links");

Expand Down Expand Up @@ -318,7 +318,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
sb.indexSegments.segment(Segments.Process.PUBLIC),
rankingProfile,
header.get(RequestHeader.USER_AGENT, ""),
false
false, 0.0d, 0.0d, 0.0d
);
Network.log.logInfo("INIT HASH SEARCH (query-" + abstracts + "): " + QueryParams.anonymizedQueryHashes(theQuery.queryHashes) + " - " + theQuery.itemsPerPage() + " links");
EventChannel.channels(EventChannel.REMOTESEARCH).addMessage(new RSSMessage("Remote Search Request from " + ((remoteSeed == null) ? "unknown" : remoteSeed.getName()), QueryParams.anonymizedQueryHashes(theQuery.queryHashes), ""));
Expand Down
26 changes: 25 additions & 1 deletion htroot/yacysearch.java
Expand Up @@ -485,6 +485,29 @@ public static serverObjects respond(
}
}

int radius = 0;
double lon = 0.0d, lat = 0.0d, rad = 0.0d;
if ((radius = querystring.indexOf("/radius/")) >= 0) {
int ve = querystring.indexOf(' ', radius + 8);
String geo = "";
if (ve < 0) {
geo = querystring.substring(radius);
querystring = querystring.substring(0, radius).trim();
} else {
geo = querystring.substring(radius, ve);
querystring = querystring.substring(0, radius) + querystring.substring(ve);
}
geo = geo.substring(8);
String[] sp = geo.split("/");
if (sp.length == 3) try {
lat = Double.parseDouble(sp[0]);
lon = Double.parseDouble(sp[1]);
rad = Double.parseDouble(sp[2]);
} catch (NumberFormatException e) {
lon = 0.0d; lat = 0.0d; rad = 0.0d;
}
}

String tenant = null;
if ( post.containsKey("tenant") ) {
tenant = post.get("tenant");
Expand Down Expand Up @@ -757,7 +780,8 @@ public static serverObjects respond(
header.get(RequestHeader.USER_AGENT, ""),
sb.getConfigBool(SwitchboardConstants.SEARCH_VERIFY_DELETE, false)
&& sb.getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false)
&& sb.peers.mySeed().getFlagAcceptRemoteIndex());
&& sb.peers.mySeed().getFlagAcceptRemoteIndex(),
lat, lon, rad);
EventTracker.delete(EventTracker.EClass.SEARCH);
EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(
theQuery.id(true),
Expand Down
20 changes: 13 additions & 7 deletions htroot/yacysearch_location.html
Expand Up @@ -20,6 +20,8 @@
var shallZoom = true; // flag if the map shall be zoomed to the search result
var shallReload = false; // flag if the search shall be repeated upon next resize of the window
var poisfound = 0;
var kmNormal = 100; // ca. 1km grid for radius
var meterNormal = 100000; // ca. 1m grid for location

// automatically adapt height of map upon window resize
function adaptHeight() {
Expand Down Expand Up @@ -66,6 +68,7 @@

function zoomChanged () {
shallZoom = false; // no automatic zoom if user hs zoomed
refreshsearch();
}

// called if a search is submitted
Expand All @@ -81,8 +84,11 @@
var center = map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
var extend = map.getExtent().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
var radius = Math.sqrt(extend.getWidth() * extend.getWidth() + extend.getHeight() * extend.getHeight()) / 2;
searchLayer_co0 = new OpenLayers.Layer.GeoRSS('Communities', path_losearch + query + '&lon=' + center.lon + '&lat=' + center.lat + '&r=' + radius + '&z=' + map.getZoom(), {'icon':marker_co});
searchLayer_md0 = new OpenLayers.Layer.GeoRSS('Point Of Interest', path_mdsearch + query + '&lon=' + center.lon + '&lat=' + center.lat + '&r=' + radius + '&z=' + map.getZoom(), {'icon':marker_md});
radius = Math.floor(radius * kmNormal + 1) / kmNormal;
var lon = Math.floor(center.lon * meterNormal) / meterNormal;
var lat = Math.floor(center.lat * meterNormal) / meterNormal;
searchLayer_co0 = new OpenLayers.Layer.GeoRSS('Communities', path_losearch + query + '&lon=' + lon + '&lat=' + lat + '&r=' + radius + '&z=' + map.getZoom(), {'icon':marker_co});
searchLayer_md0 = new OpenLayers.Layer.GeoRSS('Point Of Interest', path_mdsearch + query + '&lon=' + lon + '&lat=' + lat + '&r=' + radius + '&z=' + map.getZoom(), {'icon':marker_md});
map.addLayer(searchLayer_co0);
map.addLayer(searchLayer_md0);
//document.getElementById('apilink').setAttribute('href', 'yacysearch_location.rss?query=' + query);
Expand All @@ -92,7 +98,7 @@

function refresh() {
// check double-buffer state
if (searchLayer_md0 != null && searchLayer_md0.markers.length > 0) {
if (searchLayer_md0 != null) {
// switch the double-buffer
if (searchLayer_md1 != null) searchLayer_md1.destroy();
if (searchLayer_co1 != null) searchLayer_co1.destroy();
Expand All @@ -108,13 +114,13 @@
}
var cocount = searchLayer_co1.markers.length;
var mdcount = searchLayer_md1.markers.length;
if (mdcount + cocount <= poisfound) {
return;
}
//if (mdcount + cocount <= poisfound) {
// return;
//}

// update map and result line
poisfound = mdcount + cocount;
document.getElementById('resultline').innerHTML = poisfound + " POIs found";
document.getElementById('resultline').innerHTML = poisfound + " POIs found in visible map";

// check if any of the markers is visible on the screen.
// this is only necessary if shallZoom = false since this would set shallZoom = true
Expand Down
5 changes: 4 additions & 1 deletion htroot/yacysearch_location.java
Expand Up @@ -60,6 +60,9 @@ public static serverObjects respond(final RequestHeader header, final serverObje
final boolean search_subject = alltext || post.get("dom", "").indexOf("subject",0) >= 0;
final long maximumTime = post.getLong("maximumTime", 5000);
final int maximumRecords = post.getInt("maximumRecords", 3000);
final double lon = post.getDouble("lon", 0.0d);
final double lat = post.getDouble("lat", 0.0d);
final double radius = post.getDouble("r", 0.0d);
//i.e. http://localhost:8090/yacysearch_location.kml?query=berlin&maximumTime=2000&maximumRecords=100

int placemarkCounter = 0;
Expand Down Expand Up @@ -89,7 +92,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
// get a queue of search results
final String rssSearchServiceURL = "http://127.0.0.1:" + sb.getConfig("port", "8090") + "/yacysearch.rss";
final BlockingQueue<RSSMessage> results = new LinkedBlockingQueue<RSSMessage>();
SRURSSConnector.searchSRURSS(results, rssSearchServiceURL, query, maximumTime, Integer.MAX_VALUE, null, false, null);
SRURSSConnector.searchSRURSS(results, rssSearchServiceURL, lon == 0.0d && lat == 0.0d ? query : query + " /radius/" + lat + "/" + lon + "/" + radius, maximumTime, Integer.MAX_VALUE, null, false, null);

// take the results and compute some locations
RSSMessage message;
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/crawler/ResultURLs.java
Expand Up @@ -222,7 +222,7 @@ public static boolean remove(final String urlHash) {
public static void main(final String[] args) {
try {
final DigestURI url = new DigestURI("http", "www.yacy.net", 80, "/");
final URIMetadataRow urlRef = new URIMetadataRow(url, "YaCy Homepage", "", "", "", 0.0f, 0.0f, new Date(), new Date(), new Date(), "", new byte[] {}, 123, 42, '?', new Bitfield(), UTF8.getBytes("de"), 0, 0, 0, 0, 0, 0);
final URIMetadataRow urlRef = new URIMetadataRow(url, "YaCy Homepage", "", "", "", 0.0d, 0.0d, new Date(), new Date(), new Date(), "", new byte[] {}, 123, 42, '?', new Bitfield(), UTF8.getBytes("de"), 0, 0, 0, 0, 0, 0);
final EventOrigin stackNo = EventOrigin.LOCAL_CRAWLING;
System.out.println("valid test:\n=======");
// add
Expand Down
14 changes: 14 additions & 0 deletions source/de/anomic/server/serverObjects.java
Expand Up @@ -183,6 +183,10 @@ public double put(final String key, final float value) {
return (null == this.put(key, Float.toString(value))) ? Float.NaN : value;
}

public double put(final String key, final double value) {
return (null == this.put(key, Double.toString(value))) ? Double.NaN : value;
}

/**
* same as {@link #put(String, double)} but for integer types
* @return Returns 0 for the error case.
Expand Down Expand Up @@ -359,6 +363,16 @@ public float getFloat(final String key, final float dflt) {
}
}

public double getDouble(final String key, final double dflt) {
final String s = removeByteOrderMark(super.get(key));
if (s == null) return dflt;
try {
return Double.parseDouble(s);
} catch (final NumberFormatException e) {
return dflt;
}
}

public boolean getBoolean(final String key, final boolean dflt) {
String s = removeByteOrderMark(super.get(key));
if (s == null) return dflt;
Expand Down
4 changes: 4 additions & 0 deletions source/net/yacy/cora/services/federated/solr/SolrDoc.java
Expand Up @@ -64,6 +64,10 @@ public final void addSolr(final SolrField key, final float value) {
this.setField(key.getSolrFieldName(), value);
}

public final void addSolr(final SolrField key, final double value) {
this.setField(key.getSolrFieldName(), value);
}

public final void addSolr(final SolrField key, final boolean value) {
this.setField(key.getSolrFieldName(), value);
}
Expand Down
12 changes: 6 additions & 6 deletions source/net/yacy/document/Document.java
Expand Up @@ -87,15 +87,15 @@ public class Document {
private boolean resorted;
private final Set<String> languages;
private final boolean indexingDenied;
private final float lon, lat;
private final double lon, lat;
private final Object parserObject; // the source object that was used to create the Document

public Document(final MultiProtocolURI location, final String mimeType, final String charset,
final Object parserObject,
final Set<String> languages,
final String[] keywords, final String title, final String author, final String publisher,
final String[] sections, final String abstrct,
final float lon, final float lat,
final double lon, final double lat,
final Object text,
final Map<MultiProtocolURI, Properties> anchors,
final Map<MultiProtocolURI, String> rss,
Expand Down Expand Up @@ -400,11 +400,11 @@ public Map<String, String> getEmaillinks() {
return this.emaillinks;
}

public float lon() {
public double lon() {
return this.lon;
}

public float lat() {
public double lat() {
return this.lat;
}

Expand Down Expand Up @@ -743,7 +743,7 @@ public static Document mergeDocuments(final MultiProtocolURI location,
final Map<MultiProtocolURI, Properties> anchors = new HashMap<MultiProtocolURI, Properties>();
final Map<MultiProtocolURI, String> rss = new HashMap<MultiProtocolURI, String>();
final Map<MultiProtocolURI, ImageEntry> images = new HashMap<MultiProtocolURI, ImageEntry>();
float lon = 0.0f, lat = 0.0f;
double lon = 0.0d, lat = 0.0d;

for (final Document doc: docs) {

Expand Down Expand Up @@ -784,7 +784,7 @@ public static Document mergeDocuments(final MultiProtocolURI location,
anchors.putAll(doc.getAnchors());
rss.putAll(doc.getRSS());
ContentScraper.addAllImages(images, doc.getImages());
if (doc.lon() != 0.0f && doc.lat() != 0.0f) { lon = doc.lon(); lat = doc.lat(); }
if (doc.lon() != 0.0d && doc.lat() != 0.0d) { lon = doc.lon(); lat = doc.lat(); }
}
return new Document(
location,
Expand Down

0 comments on commit 9b4c699

Please sign in to comment.