【问题标题】:How to make full text search with mongodb spring data?如何使用mongodb spring数据进行全文搜索?
【发布时间】:2014-05-18 10:29:39
【问题描述】:

在问这个问题之前,我已经搜索了很多关于我的问题。我需要在 spring 框架中从 mongodb 进行全文搜索。到目前为止,我只是尝试了一些正则表达式,但它不满足我的要求。 例如,我有一个搜索字符串为 'increased world population' ,我的搜索算法应该返回与搜索字符串匹配良好的文档或包含搜索字符串中至少一个单词的文档。 我知道 Lucene 可以全文搜索,但我不知道如何用我的 mongodb spring 数据实现它,我不知道 spring 数据是否已经提供全文搜索。我需要一个教程来解释这一点。 到目前为止我做了什么:

Criteria textCriteri = Criteria.where("title").regex(searchStr.trim().replaceAll(" +", " "), "i");
Query query = new Query(locationCriteria).addCriteria(textCriteri).limit(Consts.MONGO_QUERY_LIMIT);
List<MyObject> advs = mongoTemplate.find(query, MyObject.class);

【问题讨论】:

    标签: spring mongodb spring-mvc full-text-search spring-data-mongodb


    【解决方案1】:

    您可以在 mongodb 中创建一个“文本”索引并通过它进行搜索,请参阅http://docs.mongodb.org/manual/core/index-text/

    根据您的搜索查询,您可能希望使用更强大的搜索引擎,例如 ElasticSearch(正如您提到的 Lucene)。

    【讨论】:

    • 我已经为我的收藏中的标题字段设置了文本索引。我只是不知道如何编写查询或使用 lucene。或者,如果可以使用正则表达式来做到这一点(就像我在问题中强调的那样),我也可以使用它。因为我现在不需要非常强大的搜索。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多