A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

【郑州校区】学成在线-第11天-讲义-搜索服务 四

4 课程搜索
4.1 需求分析

1、根据分类搜索课程信息。
2、根据关键字搜索课程信息,搜索方式为全文检索,关键字需要匹配课程的名称、 课程内容。
3、根据难度等级搜索课程。
4、搜索结点分页显示。
技术分析:
1、根据关键字搜索,采用MultiMatchQuery,搜索namedescriptionteachplan
2、根据分类、课程等级搜索采用过虑器实现。
3、分页查询。
4、高亮显示。
4.2 创建搜索服务工程


2)配置
1、配置appliction.yml

[AppleScript] 纯文本查看 复制代码
server:
port: 40100
spring:
application:
name: xc
‐
search
‐
service
elasticsearch:
hostlist: 127.0.0.1:9200 #多个结点中间用逗号分隔
course:
index: xc_course
type: doc 

2、配置RestHighLevelClientRestClient

[AppleScript] 纯文本查看 复制代码
package com.xuecheng
.search.config;
import org
.apache.http
.HttpHost;
import org
.elasticsearch.client.RestClient;
import org
.elasticsearch.client.RestHighLevelClient;
import org
.springframework.beans.factory
.annotation.Value;
import org
.springframework.context.annotation.Bean;
import org
.springframework.context.annotation.Configuration;
@Configuration
public class ElasticsearchConfig {
@Value(
"
${xuecheng
.elasticsearch.hostlist}
"
)
private String hostlist;
@Bean
public RestHighLevelClient restHighLevelClient(){
//解析hostlist配置信息
String[] split
= hostlist.split(
"
,
"
);
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray
= new HttpHost[split.length];
for(int i=
0;i<split.length;i++){
String item =
split[i];
httpHostArray[i]
= new HttpHost(item.split(
"
:
"
)[0], Integer.
parseInt(item.split(
"
:
"
)
[1]),
"
http
"
);
}
//创建RestHighLevelClient客户端
return new RestHighLevelClient(RestClient.builder(httpHostArray));
}
@Bean
public RestClient restClient(){
//解析hostlist配置信息
String[] split
= hostlist.split(
"
,
"
);
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray
= new HttpHost[split.length];
for(int i=
0;i<split.length;i++){
String item =
split[i];
httpHostArray[i]
= new HttpHost(item.split(
"
:
"
)[0], Integer.
parseInt(item.split(
"
:
"
)
[1]),
"
http
"
);
}
return RestClient.builder(httpHostArray)
.build();
}
}

4.3 API
[AppleScript] 纯文本查看 复制代码
 @Api(value
=
"
课程搜索
"
,description =
"
课程搜索
"
,tags
=
{
"
课程搜索
"
})
public interface EsCourseControllerApi {
@ApiOperation(
"
课程搜索
"
)
public QueryResponseResult<CoursePub> list(int page,int size,
CourseSearchParam courseSearchParam) throws IOException;
}



0 个回复

您需要登录后才可以回帖 登录 | 加入黑马