当前位置:网站首页>Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
2022-07-19 06:40:00 【Its natural happy clothes】
One 、RestAPI Realize automatic completion query ( Code explanation )



Code :
@Autowired
private RestHighLevelClient client;
@Test
void testSuggestion() throws IOException {
//1. Get ready Request
SearchRequest request = new SearchRequest("hotel");
//2. Get ready DSL
request.source().suggest(new SuggestBuilder().addSuggestion(
"suggestions",
SuggestBuilders.completionSuggestion("suggestion")
.prefix("hm")
.skipDuplicates(true)
.size(10)
));
//3. Initiate request
SearchResponse response = client.search(request, RequestOptions.DEFAULT);
//4. Analysis results
Suggest suggest = response.getSuggest();
//4.1 Complete the query name according to , Get more complete results
CompletionSuggestion suggestions = suggest.getSuggestion("suggestions");
//4,2 obtain options
List<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();
//4.3 Traverse
for( CompletionSuggestion.Entry.Option option : options){
String text = option.getText().toString();
System.out.println(text);
}
// System.out.println(response);
}among :
@Autowired
private RestHighLevelClient client;
We should inject bean in

Two 、 The following is the case of dark horse tourism network to realize the automatic completion function :
At the beginning of the , Input x, Can't automatically complete

RestAPI Realize automatic completion :
(1) stay controller Layer write interface

@GetMapping("suggestion")
public List<String> getSuggestions(@RequestParam("key") String predix){
return hotelService.getSuggestions(predix);
}(2) stay service Layer written

@Override
public List<String> getSuggestions(String predix) {
try {
//1. Get ready Request
SearchRequest request = new SearchRequest("hotel");
//2. Get ready DSL
request.source().suggest(new SuggestBuilder().addSuggestion(
"suggestions",
SuggestBuilders.completionSuggestion("suggestion")
.prefix(predix)
.skipDuplicates(true)
.size(10)
));
//3. Initiate request
SearchResponse response = client.search(request, RequestOptions.DEFAULT);
//4. Analysis results
Suggest suggest = response.getSuggest();
//4.1 Complete the query name according to , Get more complete results
CompletionSuggestion suggestions = suggest.getSuggestion("suggestions");
//4,2 obtain options
List<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();
//4.3 Traverse
List<String> list = new ArrayList<String>(options.size());
for( CompletionSuggestion.Entry.Option option : options){
String text = option.getText().toString();
System.out.println(text);
list.add(text);
}
return list;
} catch (IOException e) {
throw new RuntimeException();
}
}(3) Restart project
Then you can complete it automatically

边栏推荐
- [force buckle] realize queue with stack
- Interview review nth time
- ORACLE分组排序后获取第一条和最后一条值
- Manjaro 系统日常使用入门导引
- Restclient multi conditional aggregation
- Busybox 1.21.1 has udpsvd function, which can be compiled successfully without interfering with the local busybox method
- 你见过的最差的程序员是怎样的?
- Experiment 5: Gui
- 无80和443端口下申请域名SSL证书(适用于 acme.sh 和 certbot)
- [force buckle] maximum depth of binary tree
猜你喜欢

Automatic completion & (custom) Pinyin word Separator &

感知智能手機上用戶的關注狀態

Color histogram grayscale image & color image

视图、索引文件的应用

Experiment class II and object definition initialization

无80和443端口下申请域名SSL证书(适用于 acme.sh 和 certbot)
![[force buckle] copy the linked list with random pointer](/img/ed/eb54aad302da3aaac7e1d583770ca0.png)
[force buckle] copy the linked list with random pointer
![[Li Kou] a subtree of another tree](/img/96/1aaf8b8ff310677aeaabe4859eec46.png)
[Li Kou] a subtree of another tree

吴恩达机器学习第3-4章

Solution: unable to load file c:\program files\ Because running scripts is forbidden on this system
随机推荐
Positional Change of the Eyeball During Eye Movements: Evidence of Translatory Movement眼球运动过程中眼球的位
无80和443端口下申请域名SSL证书(适用于 acme.sh 和 certbot)
Dual tone sorting of CUDA and large arrays
[force buckle] maximum depth of binary tree
用头部运动学习无姿态注视偏差
Creation and implementation of WebService interface
Solutions to slow transmission speed of FileZilla virtual machine
Make config analysis of configuration commands before uboot compilation
斑点检测 记录
视图、索引文件的应用
工作中遇到的一些问题
Local makefile compile other folder files specify obj directory
虚拟现实中的眼睛跟踪
感知智能手機上用戶的關注狀態
山西省第二届网络安全技能大赛(企业组)部分赛题WP(四)
第五章 我们可以直接调用run()方法来启动一个新线程吗
实验二 类与对象定义初始化
DSL realizes automatic completion query
IDEA中@Resource爆红
[force buckle] ring list II