当前位置: 首页 > news >正文

微信网站开发视频网站500错误 虚拟主机

微信网站开发视频,网站500错误 虚拟主机,免费一级a做爰网站,阿里云服务器责任怎么做网站文章目录 ⛄引言一、分词器⛅拼音分词器⚡自定义分词器 二、自动补全查询三、自动补全⌚业务需求⏰实现酒店搜索自动补全 四、效果图⛵小结 ⛄引言 本文参考黑马 分布式Elastic search Elasticsearch是一款非常强大的开源搜索引擎#xff0c;具备非常多强大功能#xff0c;… 文章目录 ⛄引言一、分词器⛅拼音分词器⚡自定义分词器 二、自动补全查询三、自动补全⌚业务需求⏰实现酒店搜索自动补全 四、效果图⛵小结 ⛄引言 本文参考黑马 分布式Elastic search Elasticsearch是一款非常强大的开源搜索引擎具备非常多强大功能可以帮助我们从海量数据中快速找到需要的内容 像京东这样的提示应该如何实现 可通过ES实现该自动补全功能搭载分词器配合使用 本篇文章将讲解 Elastic Search 如何使用分词器实现自动补全功能以及 在项目实战中如何通过完成自动补全的需求开发 一、分词器 为什么要使用分词器呢因为我们要实现自动补全功能要对输入的文字进行分词从而更好的查询结果集 ⛅拼音分词器 要实现根据字母做补全就必须对文档按照拼音分词。在GitHub上恰好有elasticsearch的拼音分词插件。地址https://github.com/medcl/elasticsearch-analysis-pinyin ​ 下载zip安装方式如下 解压通过工具上传至 elasticsearch的plugin目录重启elasticsearch进行测试拼音分词器 重启命令 docker restart es 测试方法 POST /_analyze {text: 希尔顿酒店还不错,analyzer: pinyin }⚡自定义分词器 默认的拼音分词器会将每个汉字单独分为拼音而我们希望的是每个词条形成一组拼音需要对拼音分词器做个性化定制形成自定义分词器。 elasticsearch中分词器analyzer的组成包含三部分 character filters在tokenizer之前对文本进行处理。例如删除字符、替换字符tokenizer将文本按照一定的规则切割成词条term。例如keyword就是不分词还有ik_smarttokenizer filter将tokenizer输出的词条做进一步处理。例如大小写转换、同义词处理、拼音处理等 声明自定义分词器的语法如下 PUT /test {settings: {analysis: {analyzer: { // 自定义分词器my_analyzer: { // 分词器名称tokenizer: ik_max_word,filter: py}},filter: { // 自定义tokenizer filterpy: { // 过滤器名称type: pinyin, // 过滤器类型这里是pinyinkeep_full_pinyin: false,keep_joined_full_pinyin: true,keep_original: true,limit_first_letter_length: 16,remove_duplicated_term: true,none_chinese_pinyin_tokenize: false}}}},mappings: {properties: {name: {type: text,analyzer: my_analyzer,search_analyzer: ik_smart}}} }测试 总结 如何使用拼音分词器 下载pinyin分词器 解压并放到elasticsearch的plugin目录 重启即可 如何自定义分词器 创建索引库时在settings中配置可以包含三部分 character filter tokenizer filter 拼音分词器注意事项 为了避免搜索到同音字搜索时不要使用拼音分词器 二、自动补全查询 elasticsearch提供了Completion Suggester查询来实现自动补全功能。这个查询会匹配以用户输入内容开头的词条并返回。为了提高补全查询的效率对于文档中字段的类型有一些约束 参与补全查询的字段必须是completion类型。 字段的内容一般是用来补全的多个词条形成的数组。 比如一个这样的索引库 // 创建索引库 PUT test {mappings: {properties: {title:{type: completion}}} }然后插入下面的数据 // 示例数据 POST test/_doc {title: [Sony, WH-1000XM3] } POST test/_doc {title: [SK-II, PITERA] } POST test/_doc {title: [Nintendo, switch] }查询的DSL语句如下 // 自动补全查询 GET /test/_search {suggest: {title_suggest: {text: sw // 关键字completion: {field: title, // 补全查询的字段skip_duplicates: true, // 跳过重复的size: 10 // 获取前10条结果}}} }测试出一条数据 三、自动补全 ⌚业务需求 在页面实现 输入 文字或者拼音自动提示匹配的列表数据 根据酒店数据和地址进行查询数据列表 ⏰实现酒店搜索自动补全 现在我们的hotel索引库还没有设置拼音分词器需要修改索引库中的配置。但是我们知道索引库是无法修改的只能删除然后重新创建。 另外我们需要添加一个字段用来做自动补全将brand、suggestion、city等都放进去作为自动补全的提示。 因此总结一下我们需要做的事情包括 修改hotel索引库结构设置自定义拼音分词器修改索引库的name、all字段使用自定义分词器索引库添加一个新字段suggestion类型为completion类型使用自定义的分词器给HotelDoc类添加suggestion字段内容包含brand、business重新导入数据到hotel库 // 酒店数据索引库 PUT /hotel {settings: {analysis: {analyzer: {text_anlyzer: {tokenizer: ik_max_word,filter: py},completion_analyzer: {tokenizer: keyword,filter: py}},filter: {py: {type: pinyin,keep_full_pinyin: false,keep_joined_full_pinyin: true,keep_original: true,limit_first_letter_length: 16,remove_duplicated_term: true,none_chinese_pinyin_tokenize: false}}}},mappings: {properties: {id:{type: keyword},name:{type: text,analyzer: text_anlyzer,search_analyzer: ik_smart,copy_to: all},address:{type: keyword,index: false},price:{type: integer},score:{type: integer},brand:{type: keyword,copy_to: all},city:{type: keyword},starName:{type: keyword},business:{type: keyword,copy_to: all},location:{type: geo_point},pic:{type: keyword,index: false},all:{type: text,analyzer: text_anlyzer,search_analyzer: ik_smart},suggestion:{type: completion,analyzer: completion_analyzer}}} }修改HotelDoc实体 HotelDoc中要添加一个字段用来做自动补全内容为酒店品牌、城市、商圈等信息。按照自动补全字段的要求最好是这些字段的数组。 因此我们在HotelDoc中添加一个suggestion字段类型为ListString然后将brand、city、business等信息放到里面。 代码如下 Data NoArgsConstructor public class HotelDoc {private Long id;private String name;private String address;private Integer price;private Integer score;private String brand;private String city;private String starName;private String business;private String location;private String pic;private Object distance;private Boolean isAD;private ListString suggestion;public HotelDoc(Hotel hotel) {this.id hotel.getId();this.name hotel.getName();this.address hotel.getAddress();this.price hotel.getPrice();this.score hotel.getScore();this.brand hotel.getBrand();this.city hotel.getCity();this.starName hotel.getStarName();this.business hotel.getBusiness();this.location hotel.getLatitude() , hotel.getLongitude();this.pic hotel.getPic();//拼装数据把数据一个个放到数组中if (this.business.contains(/) || this.business.contains(、) || this.business.contains()) {String[] arr {};if (this.business.contains(/)) {arr this.business.split(/);} else if (this.business.contains(、)) {arr this.business.split(、);} else if (this.business.contains()) {arr this.business.split();}this.suggestion new ArrayList();this.suggestion.add(this.brand);//把数组中的元素一个个放进去Collections.addAll(this.suggestion, arr);} else {this.suggestion Arrays.asList(this.brand, this.business);}} }执行方法重新导入酒店数据 Testvoid testBulkRequest() throws IOException {// 查询所有的酒店数据ListHotel list hotelService.list();// 1.准备RequestBulkRequest request new BulkRequest();// 2.准备参数for (Hotel hotel : list) {// 2.1.转为HotelDocHotelDoc hotelDoc new HotelDoc(hotel);// 2.2.转jsonString json JSON.toJSONString(hotelDoc);// 2.3.添加请求request.add(new IndexRequest(hotel).id(hotel.getId().toString()).source(json, XContentType.JSON));}// 3.发送请求client.bulk(request, RequestOptions.DEFAULT);}自动补全查询API 自动补全查询DSL 对应代码 自动补全结果解析 对应代码DSL 核心源码 在Controller类新增接口 GetMapping(suggestion) public ListString getSuggestions(RequestParam(key) String prefix) {return hotelService.getSuggestions(prefix); }Service业务代码 public ListString getSuggestions(String prefix) {//1. 准备requestSearchRequest request new SearchRequest(hotel);//2. 准备DSLrequest.source().suggest(new SuggestBuilder().addSuggestion(suggestions,SuggestBuilders.completionSuggestion(suggestion).prefix(prefix).skipDuplicates(true).size(10)));try {//3. 发送请求SearchResponse response restHighLevelClient.search(request, RequestOptions.DEFAULT);//4. 解析结果Suggest suggest response.getSuggest();//根据补全查询名称获取补全结果CompletionSuggestion suggestions suggest.getSuggestion(suggestions);//获取optionsListCompletionSuggestion.Entry.Option options suggestions.getOptions();//遍历ListString result new ArrayList(options.size());for (CompletionSuggestion.Entry.Option option : options) {result.add(option.getText().toString());}return result;} catch (Exception e) { e.printStackTrace();}return null;}四、效果图 ⛵小结 以上就是【Bug 终结者】对 Spring Boot 整合分布式搜索引擎 Elastic Search 实现 自动补全功能 的简单介绍ES搜索引擎无疑是最优秀的分布式搜索引擎使用它可大大提高项目的灵活、高效性 技术改变世界 如果这篇【文章】有帮助到你希望可以给【Bug 终结者】点个赞创作不易如果有对【后端技术】、【前端领域】感兴趣的小可爱也欢迎关注❤️❤️❤️ 【Bug 终结者】❤️❤️❤️我将会给你带来巨大的【收获与惊喜】
http://www.laogonggong.com/news/138178.html

相关文章:

  • 红旗渠建设集团有限公司网站营销策划创意技巧
  • 带购物车的网站模板商会网站建设方案
  • 上海网站建设搜q.479185700wordpress tag 获取
  • asp网站源码免费下载江苏华江建设集团有限公司网站
  • 网站建设968公司登记
  • 北京网站开开发公司ip形象设计排版
  • 宁德商城网站建设建设网站域名备案
  • 临沂专门做网站的网络推广网站排行榜
  • 毕节建设局网站怎样制作免费手机网站
  • 做网站seo的公司哪家好wordpress 多站点注册
  • 装修公司网站烟台市政建设招标网站
  • 深圳苍松大厦 网站建设医院网络销售要做什么
  • 杭州公司网站网页设计二级页面
  • 石家庄大型网站建站广点通投放平台
  • 一个网站大概多少页面学做美食视频网站
  • 如何做网站布局优化硬件开发平台是什么
  • 汕头网站推广优化网站 提交入口
  • 广州做网站新锐怎么创建手机网站
  • 村网通为每个农村建设了网站门户网站开发费用
  • 猪八戒网站开发合同设计公司宣传册
  • 南昌网站搭建公司 赣ICP网上免费咨询律师电话
  • 肥西建设局官方网站郑州免费做网站的
  • 网站营销代理wordpress 仪表盘裁剪图片
  • 谁分享一个免费网站2021做网站有没有免费空间
  • 网站内部链接优化网站策划书的主题有哪些
  • 网站快速排名服务商上海服务政策调整
  • 网站开发开题报告引言定制手机软件
  • 做好档案整理及网站建设建设绿色食品网站
  • 快速html5网页设计的网站建筑公司对企业未来希望
  • 站群子网站开发怎么做网页截图