distance function of Google AppEngine Search API is behaving unconsistantly -
string loc_expr = "distance(location, geopoint(" + userlatitude + ", " + userlongitude + "))"; // build sortoptions sortoptions sortoptions = sortoptions.newbuilder() .addsortexpression(sortexpression.newbuilder().setexpression(loc_expr).setdirection(sortexpression.sortdirection.ascending).setdefaultvaluenumeric(0)) .setlimit(200).build(); // build queryoptions queryoptions options = queryoptions.newbuilder().addexpressiontoreturn(fieldexpression.newbuilder().setexpression(loc_expr).setname("distance")).setlimit(limit) .setcursor(cursor).setsortoptions(sortoptions).build(); string querystring = loc_expr + " < " + searchradius * 1000; // build query , run search query query = query.newbuilder().setoptions(options).build(querystring); indexspec indexspec = indexspec.newbuilder().setname("restaurants").build(); index index = searchservicefactory.getsearchservice().getindex(indexspec); results<scoreddocument> result = index.search(query); if (result.getnumberfound() > 0) { collection<scoreddocument> coll = result.getresults(); (scoreddocument sd : coll) { key<restaurant> key = key.create(string.valueof(sd.getid())); restaurant rest = ofy().load().key(key).now(); field f = sd.getexpressions().get(0); log.info("distance in meter : " + f.getnumber()); } }
i using above mentioned code restaurants in nearby area. following observation :-
case 1: searchradius = 0.5 km --- maximum value of distance = 0.9 km
case 2: searchradius = 1 km --- maximum value of distance = 1.8 km
case 3: searchradius = 2 km --- maximum value of distance = 2.8 km
case 4: searchradius = 3 km --- maximum value of distance = 4.8 km
why getting value of distance more radius specified?
note :- not calculating distance own. distance being returned search api.
it's known issue.
until google fix it, have filter results in code
Comments
Post a Comment