【问题标题】:multiple criteria including near and textcriteri is not working in spring data mongodb包括 near 和 textcriteri 在内的多个标准在 spring data mongodb 中不起作用
【发布时间】: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


    【解决方案1】:

    请参阅此文档:Queries cannot use both text and Geospatial Indexes 并非所有索引组合都受支持

    【讨论】:

    • 感谢您的回答。是的,你是对的。有趣的!这是一个非常常见的案例。很糟糕不能那样做。你有什么建议吗?任何用于文本搜索的高级正则表达式?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多