【发布时间】:2015-01-27 13:58:39
【问题描述】:
我正在尝试进行 geospital 查询,包括 full text search。但它不起作用。
让我分享我的代码。我的 mongo 实例是 2.6,它支持全文搜索。该查询适用于 geoNear 和类别条件。但是,当我添加 textcriteri 时,它不起作用。此外,我不知道如何从 GeoResult 获取 SEvent 对象列表。
我的第二个问题,是否可以从地理邻近查询中返回 100 多个文档?
因为根据我的要求;例如,用户将开始搜索前 1 公里以外的点。然后如果他想要更多内容,他可以问'好的,给我内容,最小 1 公里,最大 2 公里'等等......无法通过整个互联网找到有关我的问题的任何高级信息。这就是为什么寻求您的帮助。
public List<SEvent> searchEventByTxt(String txt, String catId, double longitude, double latitude) throws SowException{
Category cat = null;
Query secondQ = null;
if(!catId.equals("-1")){
cat = categoryService.findById(catId);
if (txt != null && txt.length() > 0) {
secondQ = new Query(Criteria.where("catId").is(cat.getId()).and(TextCriteria.forLanguage(new Locale(SOW.Session.current().getLang()).getLanguage()).matching(txt).getKey()));
} else {
secondQ = new Query(Criteria.where("catId").is(cat.getId()));
}
} else {
if (txt != null && txt.length() > 0) {
secondQ = new TextQuery(TextCriteria.forLanguage(new Locale(SOW.Session.current().getLang()).getLanguage()).matching(txt));
}
}
Point point = new Point(longitude, latitude);
NearQuery nq = NearQuery.near(point).maxDistance(new Distance(2, Metrics.KILOMETERS));
if(secondQ != null)
nq.query(secondQ);
GeoResults<SEvent> res = mo.geoNear(nq, Adv.class);
List<GeoResult<SEvent>> list = res.getContent();
for (GeoResult<SEvent> geoResult : list) {
System.out.println(geoResult.getContent().getTitle());
}
return null;
}
【问题讨论】:
标签: spring mongodb spring-data spring-data-mongodb