ElasticSearch+MongoDB:搜索-关键字联想

目标:

ElasticSearch+MongoDB:搜索-关键字联想_第1张图片

从长尾关键词挖掘站长工具智能改写 - 5118营销大数据中获得数据集

业务层

```java @Autowired MongoTemplate mongoTemplate;

/**
 * 联想词
 * @param userSearchDto
 * @return
 */
@Override
public ResponseResult findAssociate(UserSearchDto userSearchDto) {
    //1 参数检查
    if(userSearchDto == null || StringUtils.isBlank(userSearchDto.getSearchWords())){
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
    //分页检查
    if (userSearchDto.getPageSize() > 20) {
        userSearchDto.setPageSize(20);
    }

    //3 执行查询 模糊查询
    Query query = Query.query(Criteria.where("associateWords").regex(".*?\\" + userSearchDto.getSearchWords() + ".*"));
    query.limit(userSearchDto.getPageSize());
    List wordsList = mongoTemplate.find(query, ApAssociateWords.class);

    return ResponseResult.okResult(wordsList);
}

```

你可能感兴趣的:(elasticsearch,mongodb,大数据,搜索引擎,全文检索)