// find nearby Address objects
QueryBuilder qb1 = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.geoDistanceFilter("latlng").point(lat, lng).
distance(radius, DistanceUnit.KILOMETERS));
SearchHits hits1 = searchQueryRaw(appid, Utils.type(Address.class), qb1, pager);
if (hits1 == null) {
return new ArrayList<P>();
}
// then find their parent objects
String[] ridsarr = new String[(int) hits1.getTotalHits()];
for (int i = 0; i < hits1.getTotalHits(); i++) {
Object pid = hits1.getAt(i).getSource().get(Config._PARENTID);
if (pid != null) {
ridsarr[i] = pid.toString();
}
}
QueryBuilder qb2 = QueryBuilders.filteredQuery(QueryBuilders.queryString(query),
FilterBuilders.idsFilter(type).ids(ridsarr));
SearchHits hits2 = searchQueryRaw(appid, type, qb2, pager);
return searchQuery(appid, hits2);
}