mongodb 的 enterprise 集合存储企业信息:

{
"_id" : ObjectId("5d62b2a4380d051cfc00565b"),
"companyName" : "浙江《交通旅游导报》报业有限公司",
"companyCode" : "913300007719260474",
"provice" : "",
"city" : "",
"adress" : "",
"zipcode" : "",
"companyEmail" : "",
"contactPhone" : ",",
"source" : 1,
"date" : ISODate("2019-08-25T16:09:05.177Z"),
"_class" : "com.third.demo.entity.NewEnterprise"
}

集合的javaBean:

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field; import java.io.Serializable; @Data
@Document("enterprise")
public class GxyEnterpriseDto implements Serializable { @Field("_id")
private String practiceCompanyId; /**
* 企业名称
*/
@TextIndexed
private String companyName;
/**
* 企业代码
*/
@TextIndexed
private String companyCode;
/**
* 省份
*/
private String province;
/**
* 城市
*/
private String city;
/**
* 区域
*/
private String area;
/**
* 企业地址
*/
private String address;
/**
* 邮编
*/
private String zipcode;
/**
* 人数
*/
private String peopleNum; /**
* 经验范围
*/
private String companScope;
/**
* 企业邮箱
*/
private String companyEmail;
/**
* 是否可用
*/
private Integer state; /**
* 企业是否认证(1是 0否)
*/
private Integer isCompanyAuthen;
/**
* 电话
*/
private String contactPhone;
//1 芥末返回 2校企 3 第三方没验证过 4学生提交
private Integer source;
}

使用  @TextIndexed 注解给企业名称加上文本索引 ,拥有text index的collection才支持全文检索 。

查询的java 代码:

    public List<GxyEnterpriseDto> searchCompany(String companyName){
Query query = new Query();
// Term term = new Term();
Pageable pageable = PageRequest.of(0,50);
TextCriteria criteria = TextCriteria.forDefaultLanguage()
.matching(companyName); Criteria criteria1 =Criteria.where("source").in(1,2); query.addCriteria(criteria1);
query.addCriteria(criteria);
// Aggregation eatAggregation = Aggregation.newAggregation(
// //查询条件
// Aggregation.match(criteria),
// //查询项
// Aggregation.project("practiceCompanyId","companyName","companyCode","province","city","area","address","zipcode","peopleNum","companyType","companyTypeValue","trade","tradeValue","companScope","companyEmail","contactName","contactPhone"),
// //分组条件和聚合项
// Aggregation.group("companyCode","companyName"),
// Aggregation.limit(300)
// );
List<GxyEnterpriseDto> datas = mongoTemplate.find(query.with(pageable),GxyEnterpriseDto.class);
return datas;
}

db.getCollection('enterprise').find({ "source" : { "$in" : [1, 2] }, "$text" : { "$search" : "浙江" } })

最新文章

  1. $(document).ready,$(window).load,window.onload区别和联系
  2. Third Day:正式编程第三天,学习实践内容TextView跑马灯、AutoCompleteTextView、multiAutoCompleteTextView以及ToggleButton、checkedBox、RadioButton等相关实践
  3. 轻松实现localStorage本地存储
  4. Apache环境.htaccess伪静态301跳转(www与不带www)
  5. python笔记1
  6. NodeJS学习:爬虫小探补完计划
  7. 【HDOJ】4513 吉哥系列故事——完美队形II
  8. 【UVA】658 - It&amp;#39;s not a Bug, it&amp;#39;s a Feature!(隐式图 + 位运算)
  9. 入门VMware Workstation下的Debian学习之基本命令(二)
  10. web前端vertical-align的作用及对象详解
  11. Java的演化-Java8实战笔记
  12. Jace Config
  13. Selenium webdriver操作日历控件
  14. jQuery常用的取值或赋值的方法
  15. 【BZOJ】3295: [Cqoi2011]动态逆序对
  16. django rest_framework入门四-类视图APIView
  17. Android Studio项目提交(或更新)到github的方法
  18. Jquery获取元素的位置
  19. T&amp;F 圆桌:儿童智能玩具离我们还有多远?
  20. 【请仔细核对Git地址】关于代码量排名的说明

热门文章

  1. (2)python开发环境搭建
  2. 浅谈IT人的发展(转载)
  3. [唐胡璐]Selenium技巧- ReportNG替换TestNG默认结果报告
  4. Java8-Stream-No.06
  5. HDU 6042 - Journey with Knapsack | 2017 Multi-University Training Contest 1
  6. goproxy
  7. 模板方法(Template Method)---行为型
  8. PHP mysqli_options() 函数
  9. 部分易错JS知识点整理(缓慢填坑)
  10. 编译参数(-D)