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

西宁网站设计抖音seo搜索引擎优化

西宁网站设计,抖音seo搜索引擎优化,做个淘宝客网站怎么做的,企业推广建站效果展示 在搜索框根据拼音首字母进行提示 拼音分词器 和IK中文分词器一样的用法,按照下面的顺序执行。 # 进入容器内部 docker exec -it elasticsearch /bin/bash# 在线下载并安装 ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch…

效果展示

在搜索框根据拼音首字母进行提示

 

 

拼音分词器

和IK中文分词器一样的用法,按照下面的顺序执行。 

# 进入容器内部
docker exec -it elasticsearch /bin/bash# 在线下载并安装
./bin/elasticsearch-plugin  install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.12.1/elasticsearch-analysis-pinyin-7.12.1.zip#退出
exit
#重启容器
docker restart elasticsearch

重启完成之后进行拼音分词可以看见每个字都有,以及整个词语首字母组合成的一个。

 自定义分词器

只用默认的功能还远远不够。

先用ik进行分词,再用拼音分词器分

 

PUT /test
{"settings": {"analysis": {"analyzer": { "my_analyzer": { "tokenizer": "ik_max_word","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": {"name":{"type": "text","analyzer": "my_analyzer"}}}
}

 在test这份索引库当中再次测试就可以看见既有中文也有拼音分词了。

POST /test/_analyze
{"text":["北岭山脚鼠鼠"],"analyzer": "my_analyzer"
}

 但是这里还会有问题,用中文搜索时会把同音字也一起搜索到

指定搜索时和创建时用不同的分词器

 在上面的语句里面加上了一条

        "search_analyzer": "ik_smart"

 

POST /test/_doc/1
{"id": 1,"name": "狮子"
}
POST /test/_doc/2
{"id": 2,"name": "虱子"
}GET /test/_search
{"query": {"match": {"name": "掉入狮子笼咋办"}}
}

 结果如下

 DSL实现自动补全查询

查询补全语法

 数据准备

// 自动补全的索引库
PUT test2
{"mappings": {"properties": {"title":{"type": "completion"}}}
}
// 示例数据
POST test2/_doc
{"title": ["Sony", "WH-1000XM3"]
}
POST test2/_doc
{"title": ["SK-II", "PITERA"]
}
POST test2/_doc
{"title": ["Nintendo", "switch"]
}

 查询语句

// 自动补全查询
GET /test2/_search
{"suggest": {"title_suggest": {"text": "s", // 关键字"completion": {"field": "title", // 补全字段"skip_duplicates": true, // 跳过重复的"size": 10 // 获取前10条结果}}}
}

 

 酒店数据自动补全

修改酒店索引库数据结构

DELETE /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这个实体类里面新增一个字段suggestion,这个字段是由现有的字段组成放进去。

private List<String> suggestion;
this.suggestion= Arrays.asList(this.brand,this.business);

然后重新执行之前的批量插入的语句

 再次测试搜索可以看见搜索得到的结果里面多出了品牌和商圈信息。 

 但是这里business字段有可能是由多个的,要进行切割。

修改HotelDoc上面的构造方法的代码

        if(this.business.contains("、")){//business有多个值,需要切割String[] 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);}

再次插入数据可以看见多个词条已经分开了。 

 

 进行搜索测试

搜索所有以h开头的词条

 RestAPI实现自动补全

 请求组装+响应解析

    @Testvoid testSuggest() throws IOException {//1.准备requestSearchRequest request = new SearchRequest("hotel");//2.准备DSlrequest.source().suggest(new SuggestBuilder().addSuggestion("suggestion",SuggestBuilders.completionSuggestion("suggestion").prefix("h").skipDuplicates(true).size(10)));//3.发起请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果Suggest suggest= response.getSuggest();//4.1根据补全查询名称,获取补全结果CompletionSuggestion suggestions = suggest.getSuggestion("suggestion");//4.2获取optionsList<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();//4.3遍历for (CompletionSuggestion.Entry.Option option : options) {String text = option.getText().toString();System.out.println(text);}}

 实现搜索框自动补全

Controller中

    @GetMapping("suggestion")public List<String>getSuggestion(@RequestParam("key")String prefix){return hotelService.getSuggestions(prefix);}

Service中

    @Overridepublic List<String> getSuggestions(String prefix) {try {//1.准备requestSearchRequest request = new SearchRequest("hotel");//2.准备DSlrequest.source().suggest(new SuggestBuilder().addSuggestion("suggestion",SuggestBuilders.completionSuggestion("suggestion").prefix(prefix).skipDuplicates(true).size(10)));//3.发起请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果Suggest suggest= response.getSuggest();//4.1根据补全查询名称,获取补全结果CompletionSuggestion suggestions = suggest.getSuggestion("suggestion");//4.2获取optionsList<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();//4.3遍历List<String>list=new ArrayList<>(options.size());for (CompletionSuggestion.Entry.Option option : options) {String text = option.getText().toString();list.add(text);}return list;} catch (IOException e) {throw new RuntimeException(e);}}

效果演示

成功根据提示进行查询

 

http://www.rdtb.cn/news/15049.html

相关文章:

  • 增城做网站公司如何用网站模板建站
  • 长春市建设工程信息网厦门seo排名收费
  • 网站建设方案书写软件外包网
  • 微营销是什么青岛seo排名收费
  • 乐山住房和城乡建设厅网站百度贴吧怎么发广告
  • 做英文网站赚钱上海seo怎么优化
  • 上海网站建设-目前企业网站所面临的困惑建网站
  • 时时彩五星做号网站北京seo推广公司
  • 怎么做网站访问统计国家认可的赚钱软件
  • 手机怎么自己创造网站互联网营销的方法
  • 网页美工设计书本大连seo外包平台
  • 常平网站开发什么软件可以推广自己的产品
  • 书店网站建设需求分析调研表有效果的网站排名
  • 南京自助建站百度云搜索引擎入口盘多多
  • 政府部门建设网站流程seo好学吗入门怎么学
  • 怎么才能建立一个网站百度注册页面
  • 洛卡博网站谁做的万网域名续费
  • 9377白蛇传奇赣州seo公司
  • 电子商务网站建设 市场分析网站维护公司
  • 手机版网站制作模板企业网站建设优化
  • sgs网站开发公司处理器优化软件
  • 如何做网站怎么赚钱百度网页版浏览器入口
  • 做网站实名认证总是失败怎么回事徐州关键词优化排名
  • 制作演示网站谷歌seo优化推广
  • wordpress本地访问满郑州seo优化服务
  • 微信朋友圈的网站连接怎么做百度公司总部在哪里
  • 培训平台有哪些泰州百度关键词优化
  • 中山做网站公司哪家好宁波seo网络推广外包报价
  • 湖南省建设工程网站seo优化人员
  • 动漫制作就业方向及前景windows优化大师有用吗