ElasticSearch
拉取ElasticSearch镜像
docker pull elasticsearch:7.4.0
|
创建ElasticSearch容器
docker run -id --name elasticsearch \ -p 9200:9200 -p 9300:9300 \ -v /usr/share/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ -e "discovery.type=single-node" elasticsearch:7.4.0
|
配置中文分词器 ik
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
上传到服务器的/usr/share/elasticsearch/plugins
,解压到新建目录analysis-ik
创建索引和映射
{ "mappings": { "properties": { "id": { "type": "long" }, "publishTime": { "type": "date" }, "layout": { "type": "integer" }, "images": { "type": "keyword", "index": false }, "staticUrl": { "type": "keyword", "index": false }, "authorId": { "type": "long" }, "authorName": { "type": "text" }, "title": { "type": "text", "analyzer": "ik_smart" }, "content": { "type": "text", "analyzer": "ik_smart" } } } }
|
初始化索引库
查询文章信息,批量导入到ES索引库中
实现搜索接口
新增文章索引
文章搜索记录
用户的搜索记录,需要给每一个用户都保存一份,数据量较大,要求加载速度快,通常这样的数据存在MongoDB更合适,不建议直接存储到关系型数据库中
MongoDB
拉取镜像
创建容器
docker run -di --name mongo-service \ --restart=always -p 27017:27017 \ -v ~/data/mongodata:/data mongo
|
集成MongoDB
依赖:
pom.xml<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency>
|
配置
spring: data: mongodb: host: xxxx.xxxx.xxxx port: 27017 database: leadnews-hostory
|
映射
@Document("ap_associate_words") public class ApAssociateWords implements Serializable { private static final long serialVersionUID = 1L; private String id; private String associateWords; private Date createTime; }
|
保存搜索记录
查询搜索记录
删除搜索记录
关键字联想词
通常是网上搜索频率较高的一些词,通常在企业中有两部分来源:
第一:自己维护搜索词,通过分析用户搜索频率较高的词,按照排名作为搜索词
第二:第三方获取,关键词规划师(百度)、5118、爱站网