use of com.yahoo.prelude.Location in project vespa by vespa-engine.
the class PosSearcher method search.
public Result search(Query query, Execution execution) {
String bb = query.properties().getString(posBb);
String ll = query.properties().getString(posLl);
String xy = query.properties().getString(posXy);
if (ll == null && xy == null && bb == null) {
// Nothing to do
return execution.search(query);
}
if (query.getRanking().getLocation() != null) {
// this searcher is a NOP if there is already a location
// in the query
query.trace("query already has a location set, not processing 'pos' params", false, 1);
return execution.search(query);
}
Location loc = new Location();
loc.setDimensions(2);
String posAttribute = query.properties().getString(posAttributeName);
loc.setAttribute(posAttribute);
try {
if (ll == null && xy == null && bb != null) {
parseBoundingBox(bb, loc);
} else {
if (ll != null && xy != null) {
throw new IllegalArgumentException("Cannot handle both lat/long and xy coords at the same time");
}
if (ll != null) {
handleGeoCircle(query, ll, loc);
}
if (xy != null) {
handleXyCircle(query, xy, loc);
}
if (bb != null) {
parseBoundingBox(bb, loc);
}
}
} catch (IllegalArgumentException e) {
// System.err.println("error: "+e);
return new Result(query, ErrorMessage.createInvalidQueryParameter("Error in pos parameters: " + Exceptions.toMessageString(e)));
}
// and finally:
query.getRanking().setLocation(loc);
return execution.search(query);
}
use of com.yahoo.prelude.Location in project vespa by vespa-engine.
the class DefaultPositionSearcher method search.
@Override
public com.yahoo.search.Result search(Query query, Execution execution) {
Location location = query.getRanking().getLocation();
if (location != null && (location.getAttribute() == null)) {
IndexFacts facts = execution.context().getIndexFacts();
List<String> search = facts.newSession(query.getModel().getSources(), query.getModel().getRestrict()).documentTypes();
for (String sd : search) {
String defaultPosition = facts.getDefaultPosition(sd);
if (defaultPosition != null) {
location.setAttribute(defaultPosition);
}
}
if (location.getAttribute() == null) {
location.setAttribute(facts.getDefaultPosition(null));
}
}
return execution.search(query);
}
use of com.yahoo.prelude.Location in project vespa by vespa-engine.
the class LocationTestCase method testAspect.
public void testAspect() {
// 0 degrees latitude, on the equator
Location loc1 = new Location("[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,CalcLatLon)");
assertEquals(loc1.toString(), "[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,4294967295)");
// 90 degrees latitude, on the north pole
Location loc2 = new Location("[2,-1110000,330000,-1160000,340000](2,-1100222,90000000,300,0,1,0,CalcLatLon)");
assertEquals(loc2.toString(), "[2,-1110000,330000,-1160000,340000](2,-1100222,90000000,300,0,1,0)");
Location loc3 = new Location("attr1:[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,CalcLatLon)");
assertEquals(loc3.toString(), "attr1:[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,4294967295)");
}
Aggregations