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

怎样注册网站帐号申请wordpress快速赚钱

怎样注册网站帐号申请,wordpress快速赚钱,手机网站开发c 教程,wordpress 取消标签Elasticsearch#xff1a;一个分布式的、Restful 风格的搜索引擎#xff1b;支持对各种类型的数据的索引#xff1b;搜索速度快#xff0c;可以提供实时的搜索服务#xff1b;便于水平扩展#xff0c;每秒可以处理 PB 级海量数据 目录 1.Spring 整合 Elasticsearch 1.1…Elasticsearch一个分布式的、Restful 风格的搜索引擎支持对各种类型的数据的索引搜索速度快可以提供实时的搜索服务便于水平扩展每秒可以处理 PB 级海量数据 目录 1.Spring 整合 Elasticsearch 1.1 实体类与 ES 建立关系  1.2 实现接口 1.3 测试类 1.Spring 整合 Elasticsearch 引入依赖spring-boot-starter-data-elasticsearch配置 Elasticsearchcluster-name、cluster-notesSpring Data ElaticsearchElaticsearchRestTemplate、ElaticsearchRepository 依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId /dependency 配置 # ElasticsearchProperties spring.data.elasticsearch.cluster-namexiaowen spring.data.elasticsearch.cluster-nodes127.0.0.1:9300 解决冲突Elasticsearch 底层是基于 NettyRedis 底层也是基于 Netty两者启动 natty 的时候由冲突 在 Application 类核心入口配置类最先被加载的添加 添加 PostConstruct 注解管理 Bean 的初始化方法由注解所修饰的方法会在构造器调用完成之后被执行添加方法解决 netty 启动冲突问题Netty4Utils.setAvailableProcessors() package com.example.demo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import javax.annotation.PostConstruct;SpringBootApplication public class DemoApplication {//添加 PostConstruct 注解管理 Bean 的初始化方法由注解所修饰的方法会在构造器调用完成之后被执行PostConstructpublic void init() {// 解决netty启动冲突问题// see Netty4Utils.setAvailableProcessors()System.setProperty(es.set.netty.runtime.available.processors, false);}public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}} 1.1 实体类与 ES 建立关系  编写与需求相关的代码把数据库中存的帖子再存到 ES 服务器中在 ES 服务器中搜索帖子 帖子表存到 ES 中的索引每个字段对应的类型、怎么搜索都是要进行配置但是配置不需要写 xml 文件通过注解实现注解写在实体类中针对帖子操作写在 discussPost 类中 在此类中添加注解 Document(indexName , type , shards   , replicas   )Spring 整合 ES底层访问 ES 会自动将实体数据和 ES 服务器的索引映射indexName索引type类型shards分片replicas副本ElasticSearch7.x已经不推荐使用type了并且将在8.0彻底移除主键通常会加 Id、普通字段添加 Field(type FiledType. )重点是 title 和 context搜索帖子主要搜索标题和内容类型为 type FieldType.Text存储的时候尽可能多的拆分关键词增加搜索范围使用 analyzer ik_max_word搜索的时候需要尽可能满足需求不需要拆分太多次使用searchAnalyzer ik_smart /*** 与 ES 中的索引对应*///Spring 整合 ES底层访问 ES 会自动将实体数据和 ES 服务器的索引映射 Document(indexName discusspost) public class DiscussPost {Idprivate int id;Field(type FieldType.Integer)private int userId;//搜索帖子主要搜索标题和内容//存储的时候尽可能多的拆分关键词增加搜索范围使用 analyzer ik_max_word// 搜索的时候需要尽可能满足需求不需要拆分太多次使用searchAnalyzer ik_smartField(type FieldType.Text, analyzer ik_max_word, searchAnalyzer ik_smart)private String title;Field(type FieldType.Text, analyzer ik_max_word, searchAnalyzer ik_smart)private String content;Field(type FieldType.Integer)private int type;Field(type FieldType.Integer)private int status;//帖子状态Field(type FieldType.Date)private Date createTime;//创建时间Field(type FieldType.Integer)private int commentCount;//评论数量Field(type FieldType.Double)private double score;//分数 } 上述这个实体类就和es之间的数据建立了联系。 1.2 实现接口 在dao下新建elasticsearch实现 DiscussPostRepository 接口继承时声明泛型主键类型 添加注解 Repository这个接口是数据访问层代码ES可以看作特殊的数据库Mapper 是 MyBatis 专用注解 package com.example.demo.dao.elasticsearch;import com.example.demo.entity.DiscussPost; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.stereotype.Repository;Repository public interface DiscussPostRepository extends ElasticsearchRepositoryDiscussPost, Integer {} 1.3 测试类 package com.example.demo;import com.example.demo.dao.DiscussPostMapper; import com.example.demo.dao.elasticsearch.DiscussPostRepository; import com.example.demo.entity.DiscussPost; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.PageRequest; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.SearchHit; import org.springframework.data.elasticsearch.core.SearchHits; import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner;import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map;RunWith(SpringRunner.class) SpringBootTest ContextConfiguration(classes DemoApplication.class) public class ElasticsearchTests {Autowiredprivate DiscussPostMapper discussMapper;Autowiredprivate DiscussPostRepository discussRepository;Autowiredprivate ElasticsearchRestTemplate elasticsearchRestTemplate;//查询Testpublic void testInsert() {discussRepository.save(discussMapper.selectDiscussPostById(241));discussRepository.save(discussMapper.selectDiscussPostById(242));discussRepository.save(discussMapper.selectDiscussPostById(243));}//插入多条数据Testpublic void testInsertList() {discussRepository.saveAll(discussMapper.selectDiscussPosts(101, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(102, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(103, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(111, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(112, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(131, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(132, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(133, 0, 100));discussRepository.saveAll(discussMapper.selectDiscussPosts(134, 0, 100));}//修改Testpublic void testUpdate() {DiscussPost post discussMapper.selectDiscussPostById(231);post.setContent(我是新人,使劲灌水.);discussRepository.save(post);}//删除Testpublic void testDelete() {// discussRepository.deleteById(231);discussRepository.deleteAll();}//搜索Testpublic void testSearchByRepository() {NativeSearchQuery searchQuery new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery(互联网寒冬, title, content)).withSorts(SortBuilders.fieldSort(type).order(SortOrder.DESC),SortBuilders.fieldSort(score).order(SortOrder.DESC),SortBuilders.fieldSort(createTime).order(SortOrder.DESC)).withPageable(PageRequest.of(0, 10)).withHighlightFields( //高亮显示new HighlightBuilder.Field(title).preTags(em).postTags(/em),new HighlightBuilder.Field(content).preTags(em).postTags(/em)).build();// elasticTemplate.queryForPage(searchQuery, class, SearchResultMapper)// 底层获取得到了高亮显示的值, 但是没有返回.IterableDiscussPost page discussRepository.findAll();for (DiscussPost post : page) {System.out.println(post);}}// 查询数据并将关键字高亮显示Testpublic void testSearchByTemplate() {// withQuery()用于构造搜索条件NativeSearchQuery searchQuery new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery(互联网寒冬, title, content)).withSorts(SortBuilders.fieldSort(type).order(SortOrder.DESC),SortBuilders.fieldSort(score).order(SortOrder.DESC),SortBuilders.fieldSort(createTime).order(SortOrder.DESC)).withPageable(PageRequest.of(0, 10)).withHighlightFields(new HighlightBuilder.Field(title).preTags(em).postTags(/em),new HighlightBuilder.Field(content).preTags(em).postTags(/em)).build();//查询SearchHitsDiscussPost search elasticsearchRestTemplate.search(searchQuery, DiscussPost.class);long count elasticsearchRestTemplate.count(searchQuery, DiscussPost.class);System.out.println(共查询到: count 条数据);//得到查询返回的内容ListSearchHitDiscussPost searchHits search.getSearchHits();// 设置一个最后需要返回的实体类集合ListDiscussPost discussPosts new ArrayList();// 遍历返回的内容进行处理for (SearchHitDiscussPost hit : searchHits) {// 获取高亮的内容MapString, ListString highlightFields hit.getHighlightFields();// 将高亮的内容添加到content中(匹配到的如果是多段就将第一段高亮显示)// 没有匹配到关键字就显示原来的title和contenthit.getContent().setTitle(highlightFields.get(title)null ? hit.getContent().getTitle():highlightFields.get(title).get(0));hit.getContent().setContent(highlightFields.get(content)null ? hit.getContent().getContent():highlightFields.get(content).get(0));// 放到实体类中discussPosts.add(hit.getContent());}for (DiscussPost post : discussPosts) {System.out.println(post);}} }
http://www.pierceye.com/news/28326/

相关文章:

  • 网站建设需要多长时间seo网站优化
  • 有关网站建设新闻资讯上海自贸区注册企业优惠政策
  • 网站策划的具体内容是什么有什么网站可以接单做兼职的
  • 广州做包包的网站好百度上怎么发布作品
  • 邦泽网站建设semi是什么意思
  • 服装商店的网站建设要求网站想上线怎么做
  • 百度怎样建设网站东莞整合网站建设推广
  • 网站的设计与实现苏州本地网站有哪些
  • 公众号如何做网站wordpress创建小工具栏
  • 公司多个门户是做二级域名还是做多个网站造价信息网官网
  • 小米官方网站开发版wordpress好用的插件
  • 兰州做网站的公司网站建设管理报告
  • 做一手房用什么网站好网站开发集成工具
  • 2021国内最好用免费建站系统怎么网站建设怎么样
  • 个体可以做几个网站什么购物软件好用
  • 山东省建设监理协会官方网站重庆电力建设设计公司网站
  • 优质的营销网站建设怎么在建设银行网站挂号
  • 如果做网站需要多少钱wordpress加图片水印
  • 公司网站格式广州网站建设哪家强
  • 网站建设服务器主板1150针网站建设及相关流程图
  • 机械公司网站建设镇江关键字优化品牌
  • 大连企业网站建设静态网站末班
  • 网站个人备案麻烦吗网站建设的业务员
  • 网站建设需要包含什么最大的开源网站
  • 加强网站信息内容建设管理简洁大方 网站
  • 温州网站建设推广东莞关键词优化免费诊断
  • 365做网站青海省住房建设厅网站首页
  • 建立中文网站的英文杭州建设网通知公告栏
  • 郑州网站设计见效快佛山设计公司
  • 泉州 网站制作游戏网站推广