mongodb全文搜索
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" : "浙江" } })
mongodb全文搜索的更多相关文章
- MongoDB全文搜索——目前尚不支持针对特定field的搜索
> db.articles.createIndex( { subject: "text" } ) { "createdCollectionAutomatically ...
- HubbleDotNet开源全文搜索数据库项目--技术详解
HubbleDotNet 简介 HubbleDotNet 和 Lucene.net 性能对比测试 HubbleDotNet 和 Lucene.Net 匹配相关度的比较 HubbleDotNet 软件架 ...
- Flask 教程 第十六章:全文搜索
本文翻译自The Flask Mega-Tutorial Part XVI: Full-Text Search 这是Flask Mega-Tutorial系列的第十六部分,我将在其中为Microblo ...
- SQLSERVER全文搜索
SQLSERVER全文搜索 看这篇文章之前请先看一下下面我摘抄的全文搜索的MSDN资料,基本上MSDN上关于全文搜索的资料的我都copy下来了 并且非常认真地阅读和试验了一次,并且补充了一些SQL语句 ...
- [Elasticsearch] 全文搜索 (一) 基础概念和match查询
全文搜索(Full Text Search) 现在我们已经讨论了搜索结构化数据的一些简单用例,是时候开始探索全文搜索了 - 如何在全文字段中搜索来找到最相关的文档. 对于全文搜索而言,最重要的两个方面 ...
- coreseek实战(三):全文搜索在php中应用(使用api接口)
coreseek实战(三):全文搜索在php中应用(使用api接口) 这一篇文章开始学习在php页面中通过api接口,使用coreseek全文搜索. 第一步:综合一下前两篇文章,coreseek实战( ...
- mysql 全文搜索的FULLTEXT
FULLTEXT索引 创建FULLTEXT索引语法 创建table的时候创建fullText索引 CREATE TABLE table_name( column1 data_type, column2 ...
- paip.mysql fulltext 全文搜索.最佳实践.
paip.mysql fulltext 全文搜索.最佳实践. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blo ...
- 命令行的全文搜索工具--ack
想必大家在命令行环境下工作时候,一定有想要查找当前目录下的源代码文件中的某些字符的需求,这时候如果使用传统方案,你可能需要输入一长串的命令,比如这样: 1. grep -R 'string' dir/ ...
随机推荐
- 使用canvas 代码画小猪佩奇
最近不是小猪佩奇很火嘛!!! 前几天 在知乎 看见了别人大佬用python写的 小猪佩奇, 顿时想学 ,可是 自己 没学过python(自己就好爬爬图片,,,,几个月没用 又丢了) 然后 就想画一个 ...
- VS---《在VS2010中 使用C++创建和使用DLL》(001)
VS---<在VS2010中 使用C++创建和使用DLL>(001) 需要学习制作和使用动态库,现在知道:DLL调用有两种方式,一种是静态调用,另外一种是动态调用.详细的还不算明白,等后期 ...
- pip安装tesserocr时报错
在Xubuntu上的python2虚拟环境中, 使用pip安装tesserocr时报错error: command 'x86_64-linux-gnu-gcc' failed with exit st ...
- python 判断数据类型及释疑
Python 判断数据类型有type和isinstance 基本区别在于: type():不会认为子类是父类 isinstance():会认为子类是父类类型 class Color(object): ...
- 《黑白团团队》第九次团队作业:Beta冲刺第二天
项目 内容 作业课程地址 任课教师首页链接 作业要求 团队项目 填写团队名称 黑白团团队 填写具体目标 认真负责,完成项目 团队项目Github仓库地址链接. 第一天 日期:2019/6/24 1.1 ...
- 微信小程序开发框架 Wepy 的使用
一.github地址:https://github.com/Tencent/wepy 按照 README.md 的步骤进行操作: 1.在“介绍”中获得 wepy 的开发资源汇总:https://git ...
- ActiveMQ初步安装使用(一)
ActiveMQ 的官网 : http://activemq.apache.org ActiveMQ 扩展出: API 接受发送 MQ 的高可用 MQ 的集群容错配置 MQ 的持久化 延时发送 签收机 ...
- 前端知识体系:JavaScript基础-一个原型继承例子
function Elem(id) { this.elem = document.getElementById(id); } Elem.prototype.html = function(val){ ...
- vs调试代码 提示 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。
未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项.试图加载格式不正确的程序. 1.调试-选项-项目和解决方案-web项目-勾选对网站和项目使用iis express 64 ...
- nginx 之 root和alias
转载: https://www.jianshu.com/p/4be0d5882ec5 https://blog.csdn.net/Erica_1230/article/details/7855311 ...