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全文搜索的更多相关文章

  1. MongoDB全文搜索——目前尚不支持针对特定field的搜索

    > db.articles.createIndex( { subject: "text" } ) { "createdCollectionAutomatically ...

  2. HubbleDotNet开源全文搜索数据库项目--技术详解

    HubbleDotNet 简介 HubbleDotNet 和 Lucene.net 性能对比测试 HubbleDotNet 和 Lucene.Net 匹配相关度的比较 HubbleDotNet 软件架 ...

  3. Flask 教程 第十六章:全文搜索

    本文翻译自The Flask Mega-Tutorial Part XVI: Full-Text Search 这是Flask Mega-Tutorial系列的第十六部分,我将在其中为Microblo ...

  4. SQLSERVER全文搜索

    SQLSERVER全文搜索 看这篇文章之前请先看一下下面我摘抄的全文搜索的MSDN资料,基本上MSDN上关于全文搜索的资料的我都copy下来了 并且非常认真地阅读和试验了一次,并且补充了一些SQL语句 ...

  5. [Elasticsearch] 全文搜索 (一) 基础概念和match查询

    全文搜索(Full Text Search) 现在我们已经讨论了搜索结构化数据的一些简单用例,是时候开始探索全文搜索了 - 如何在全文字段中搜索来找到最相关的文档. 对于全文搜索而言,最重要的两个方面 ...

  6. coreseek实战(三):全文搜索在php中应用(使用api接口)

    coreseek实战(三):全文搜索在php中应用(使用api接口) 这一篇文章开始学习在php页面中通过api接口,使用coreseek全文搜索. 第一步:综合一下前两篇文章,coreseek实战( ...

  7. mysql 全文搜索的FULLTEXT

    FULLTEXT索引 创建FULLTEXT索引语法 创建table的时候创建fullText索引 CREATE TABLE table_name( column1 data_type, column2 ...

  8. paip.mysql fulltext 全文搜索.最佳实践.

    paip.mysql fulltext 全文搜索.最佳实践.  作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blo ...

  9. 命令行的全文搜索工具--ack

    想必大家在命令行环境下工作时候,一定有想要查找当前目录下的源代码文件中的某些字符的需求,这时候如果使用传统方案,你可能需要输入一长串的命令,比如这样: 1. grep -R 'string' dir/ ...

随机推荐

  1. 12_Hive实战案例_累计报表_级联求和

    注:Hive面试题:累积报表 数据文件: 有如下访客访问次数统计表 t_access_times 需要输出报表:t_access_times_accumulate 实现步骤: 创建表,并将数据加载到表 ...

  2. P2050 [NOI2012]美食节 动态加边加点

    修车数据加强版 需要动态加边加点 #include<bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; , MA ...

  3. python中else与finally的总结

    1.else的用法 对try...except的补充: else子句的使用比在子句中添加其他代码更好,try因为它避免了意外捕获由try... except语句保护的代码未引发的异常. for arg ...

  4. HDU 5634 (线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5634 题意:给出 n 个数,有三种操作,把区间的 ai 变为 φ(ai):把区间的 ai 变为 x:查 ...

  5. Codeforces Round #590 (Div. 3) A. Equalize Prices Again

    链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistan ...

  6. 错误信息:[ERR] Sorry, can't connect to node 10.211.55.8:7001

    错误信息: [root@centos-linux redis-cluster]# ./redis-trib.rb create --replicas 1 10.211.55.8:7001 10.211 ...

  7. SuperSocket实例

    下载地址:https://files.cnblogs.com/files/xixixing/ConsoleApp.zip 创建控制台应用程序:ConsoleApp MySession.cs using ...

  8. 如何在 Laravel 中灵活的使用 Trait

    如何在 Laravel 中灵活的使用 Trait  Laravel/ 3个月前/  1740 /  4 / 更新于 3个月前   @这是小豪的第九篇文章 好久没有更新文章了,说好了周更结果还是被自己对 ...

  9. BZOJ 2815: [ZJOI2012]灾难 拓扑排序+倍增LCA

    这种问题的转化方式挺巧妙的. Code: #include <bits/stdc++.h> #define N 100000 #define M 1000000 #define setIO ...

  10. INLINE HOOK过简单驱动保护的理论知识和大概思路

    这里的简单驱动保护就是简单的HOOK掉内核API的现象 找到被HOOK的函数的当前地址在此地址处先修改页面保护属性然后写入5个字节.5个字节就是一个简单的JMP指令.这里说一下JMP指令,如下: 00 ...