Start to use ElasticSearch (5) search box association tips

  前几天工作比较忙没有过来写,今天趁着有点空我来跟大家一起研究一下搜索提示框联想。

Let's take a look at Baidu's search box first. Very plain and simple. As a search engine, the recommended search terms are just convenient for you to use for
further searches.
Logically, my personal feeling is 10, so the ranking should be the first 10 records in reverse order according to the search rate.
There should be a lot of data that can be matched here, but if all are loaded in, it will look very long, and the speed will be slow.

Start to use ElasticSearch (5) search box association tips

Use of Typeahead

In order to improve efficiency, I chose a mature and easy-to-use search prompt framework, Typeahead.js produced by Twitter.
Source address: https://github.com/twitter/typeahead.js

Start to use ElasticSearch (5) search box association tips

Typeahead needs to rely on jQuery 1.9+, we first create a simple static page called index.html.
Download jQuery and Typeahead JS.
First build a demo page index.html, the content is as follows.

Start to use ElasticSearch (5) search box association tips

Basically, the input binding should be seen very clearly. Find the class=typeahead binding method under id=demo.
The hint below is the hint, the main one is source: data source.
var suggestions = ['test1','test2','test3','ceshi1','ceshi2','ceshi3'];
I am hard-coded here. You can use post to go to the background to request data sources.
Then let me see the effect.
Start to use ElasticSearch (5) search box association tips

Start to use ElasticSearch (5) search box association tips
I didn't add styles because of testing. You can add your favorite styles if you need it.

Guess you like

Origin blog.51cto.com/15034497/2571658