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/ ...
随机推荐
- Elasticsearch下载安装
本文链接:https://blog.csdn.net/yjclsx/article/details/81302041注:Elasticsearch 需要 Java 8 环境,在安装Elasticsea ...
- new函数
可以通过new函数直接创建一个类型的指针 变量名:=new(Type) 使用new函数创建的指针已有指向,可以使用*指针对象进行赋值. func main() { a := new(int) fmt. ...
- 统计连接到主机前十的ip地址和连接数
常用脚本–tcp #!/bin/bash # #******************************************************************** #encodi ...
- Aizu - 1382 Black or White (分段决策,单调队列优化dp)
题意:给定只有黑白两种颜色的序列A,B,每次可以选择一段连续的长度不超过k的区间将其染成同一种颜色,求把序列A变成B所需的最小操作次数. 首先需要找出一些最优解的特征: 1.如果序列A的第一个颜色和B ...
- Spring Security 自定义 登陆 权限验证
转载于:https://www.jianshu.com/p/6b8fb59b614b 项目简介 基于Spring Cloud 的项目,Spring Cloud是在Spring Boot上搭建的所以按照 ...
- Luogu P4398 [JSOI2008]Blue Mary的战役地图 矩阵哈希
其实可以二分矩阵边长但是我太懒了$qwq$. 把每个子矩阵扔到$map$里,然后就没了 #include<cstdio> #include<map> #include<i ...
- js 获取当前focus 的 input 元素
document.querySelector("#pro-code").focus(); console.log("focus:" + document.act ...
- [Luogu] 火柴排队
https://www.luogu.org/problemnew/show/P1966 离散化 树状数组求逆序对个数 #include <bits/stdc++.h> using name ...
- 数据结构实验之链表一:顺序建立链表(SDUT 2116)
Problem Description 输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据. Input 第一行输入整数的个数N: 第二行依次输入每个整数. Output ...
- Codeforces 576D Flights for Regular Customers (图论、矩阵乘法、Bitset)
题目链接 http://codeforces.com/contest/576/problem/D 题解 把边按\(t_i\)从小到大排序后枚举\(i\), 求出按前\((i-1)\)条边走\(t_i\ ...