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

wordpress添加og标签seo搜索工具栏

wordpress添加og标签,seo搜索工具栏,金华东阳网站建设,自己制作的网站如何发布注意!!!博主只在测试环境试了一下,没有发到生产环境跑。因为代码还没写完客户说不用弄了( •̩̩̩̩_•̩̩̩̩ ) 也好,少个功能少点BUG 使用from size的时候发现存在max_result_window10000的限制&…

注意!!!博主只在测试环境试了一下,没有发到生产环境跑。因为代码还没写完客户说不用弄了( •̩̩̩̩_•̩̩̩̩ ) 也好,少个功能少点BUG

使用from + size的时候发现存在max_result_window=10000的限制,于是研究使用别的方法,最终想出个歪招来实现深度分页跳页。

1、三种分页方式比较

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、实现过程

  • BaseEsMapper构建查询条件
  • RestHighLevelClient实现scroll大分页滚动查询
  • 判断是否跨页,如果跨页滚动拿到两页数据
  • 根据前端分页参数进行数据截取返回

3、实现代码

引入依赖

<dependency><groupId>org.dromara.easy-es</groupId><artifactId>easy-es-boot-starter</artifactId><version>2.0.0</version>
</dependency>
<dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-client</artifactId><version>7.6.2</version>
</dependency>
<dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.6.2</version>
</dependency>

SearchResult

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;@Data
public class SearchResult<T> implements Serializable {private int total;private List<DocBaseEntity<T>> source = new ArrayList<>();private JSONObject aggregations;private String scrollId;public void addData(DocBaseEntity<T> obj){source.add(obj);}public List<T> getDatas(){return source.stream().map(DocBaseEntity::getDatas).collect(Collectors.toList());}public void addDatas(List<DocBaseEntity<T>> objs){source.addAll(objs);}public void setTotal(Object total){this.total = Integer.parseInt(String.valueOf(total));}public JSONObject toJSONObject(){return JSONUtil.parseObj(this,true);}
}

DocBaseEntity

import cn.hutool.json.JSONObject;
import lombok.Data;
import org.elasticsearch.search.SearchHit;
import java.io.Serializable;@Data
public class DocBaseEntity<T> implements Serializable {private String _index;private String _type;private String _id;private T datas;public DocBaseEntity(SearchHit data) {this._index = data.getIndex();this._type = data.getType();this._id = data.getId();}public DocBaseEntity(JSONObject jsonHits){this._index = jsonHits.getStr("_index");this._type = jsonHits.getStr("_type");this._id = jsonHits.getStr("_id");}public T getDatas(){return datas;}}

RestClientConfig

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class RestClientConfig {@Value("${elasticsearch.clientIps}")private String clientIps;@Value("${elasticsearch.httpPort}")private int httpPort;@Value("${elasticsearch.username}")private String username;@Value("${elasticsearch.password}")private String password;private HttpHost[] getHttpHosts(String clientIps, int esHttpPort) {String[] clientIpList = clientIps.split(",");HttpHost[] httpHosts = new HttpHost[clientIpList.length];for (int i = 0; i < clientIpList.length; i++) {httpHosts[i] = new HttpHost(clientIpList[i], esHttpPort, "http");}return httpHosts;}/*** 创建带HTTP Basic Auth认证rest客户端*/@Beanpublic RestHighLevelClient restHighLevelClient() {CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));return new RestHighLevelClient(RestClient.builder(getHttpHosts(clientIps, httpPort)).setHttpClientConfigCallback((HttpAsyncClientBuilder httpAsyncClientBuilder) -> httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider)));}
}

滚动查询方法

@Autowired
private RestHighLevelClient restHighLevelClient;/*** 滚动查询* @param indexName* @param pageNo* @param pageSize* @param scrollId* @param resultObj* @param wrapper* @param <T>* @return* @throws IOException*/
public <T> SearchResult<T> scrollSearchElasticSearchDatas(String indexName,int pageNo,int pageSize,String scrollId,Class<T> resultObj,LambdaEsQueryWrapper<ES实体类Bean> wrapper) throws IOException {SearchSourceBuilder searchSourceBuilder = rdsBookCommonDetailEsMapper.getSearchSourceBuilder(wrapper);searchSourceBuilder.size(pageSize);SearchRequest searchRequest = new SearchRequest(indexName);searchRequest.source(searchSourceBuilder);//设定scroll失效时长Scroll scroll = new Scroll(TimeValue.timeValueMinutes(3));searchRequest.scroll(scroll);SearchResponse searchResponse = null;if(StrUtil.isEmpty(scrollId)){searchResponse = executSearch(searchRequest);String tempscrollId = searchResponse.getScrollId();SearchScrollRequest searchScrollRequest = new SearchScrollRequest(tempscrollId);searchScrollRequest.scroll(scroll);for (int i = 0; i < (pageNo -1); i++) {searchResponse = scrollSearch(searchScrollRequest);}scrollId = tempscrollId;}else {SearchScrollRequest searchScrollRequest = new SearchScrollRequest(scrollId);searchResponse = scrollSearch(searchScrollRequest);}//构建结果SearchResult<T> result = createSearchResult(searchResponse,resultObj);result.setScrollId(scrollId);return result;
}/*** 执行查询*/
private SearchResponse executSearch(SearchRequest searchRequest)     {SearchResponse searchResponse = null;try{searchResponse = restHighLevelClient.search(searchRequest,RequestOptions.DEFAULT);}catch(Exception e){//异常处理}return searchResponse;
}/*** 滚动查询执行* @param searchScrollRequest* @return*/
private  SearchResponse scrollSearch(SearchScrollRequest searchScrollRequest){SearchResponse searchResponse = null;try{searchResponse = restHighLevelClient.scroll(searchScrollRequest,RequestOptions.DEFAULT);}catch(Exception e){//异常处理}return searchResponse;
}/*** 构建目标结果* @param response 返回参数* @param resultObj 类对象* @param <T>* @return*/
private <T> SearchResult<T> createSearchResult(SearchResponse response,Class<T> resultObj){SearchResult<T> resultMap = new SearchResult<>();SearchHit[] datas = response.getHits().getHits();for(SearchHit data:datas){DocBaseEntity<T> temp = new DocBaseEntity<>(data);temp.setDatas(JSONUtil.toBean(JSONUtil.parseObj(data.getSourceAsMap()),resultObj));resultMap.addData(temp);}resultMap.setTotal(response.getHits().getTotalHits().value);return resultMap;
}/*** 关闭scroll* @param scrollId* @throws IOException*/
private void clearScrollSession(String scrollId) throws IOException {if (scrollId != null) {ClearScrollRequest clearScrollRequest = new ClearScrollRequest();clearScrollRequest.addScrollId(scrollId);ClearScrollResponse clearScrollResponse = restHighLevelClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);clearScrollResponse.isSucceeded();}
}

使用

LambdaEsQueryWrapper<ES实体类Bean> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eqxxx
...构建各种查询条件
// 游标id
String scrollId = "";
// 第一次查询
SearchResult<ES实体类Bean> firstSearchResult = null;
// 第二次查询
SearchResult<ES实体类Bean> secondSearchResult = null;
// 每次滚动查询5000条数据,根据前端传的分页参数决定要滚动到哪一页
int maxPage = ((searchCommonDetaiVo.getCurrentPage() * searchCommonDetaiVo.getPageSize()) / 5000) + 1;
try {firstSearchResult = scrollSearchElasticSearchDatas("IndexName", maxPage, 5000, scrollId, ES实体类Bean.class, wrapper);scrollId = firstSearchResult.getScrollId();
} catch (IOException e) {e.printStackTrace();
}
// 判断是否跨页
if (searchCommonDetaiVo.getPageSize() > (searchCommonDetaiVo.getCurrentPage() * searchCommonDetaiVo.getPageSize()) % 5000) {try {secondSearchResult = scrollSearchElasticSearchDatas("IndexName", maxPage-1, 5000, scrollId, ES实体类Bean.class, wrapper);} catch (IOException e) {e.printStackTrace();}
}
// TODO 根据前端分页参数截取数据返回
try {clearScrollSession(scrollId);
} catch (IOException e) {log.info("游标清理失败");e.printStackTrace();
}

文章转载自:
http://theftproof.bpcf.cn
http://mirex.bpcf.cn
http://testiness.bpcf.cn
http://sharpy.bpcf.cn
http://remark.bpcf.cn
http://pustulant.bpcf.cn
http://incontinent.bpcf.cn
http://lack.bpcf.cn
http://pentagonese.bpcf.cn
http://mistrial.bpcf.cn
http://recess.bpcf.cn
http://volatile.bpcf.cn
http://votress.bpcf.cn
http://pollination.bpcf.cn
http://influential.bpcf.cn
http://abductor.bpcf.cn
http://videography.bpcf.cn
http://advect.bpcf.cn
http://bedash.bpcf.cn
http://powerful.bpcf.cn
http://brickmason.bpcf.cn
http://xiphophyllous.bpcf.cn
http://permissibly.bpcf.cn
http://brassin.bpcf.cn
http://rubbed.bpcf.cn
http://anthropophagi.bpcf.cn
http://vaccinization.bpcf.cn
http://pawpaw.bpcf.cn
http://blindfish.bpcf.cn
http://rasp.bpcf.cn
http://mallein.bpcf.cn
http://successor.bpcf.cn
http://chingkang.bpcf.cn
http://bullyboy.bpcf.cn
http://swelldom.bpcf.cn
http://seminate.bpcf.cn
http://tattler.bpcf.cn
http://garrigue.bpcf.cn
http://heelball.bpcf.cn
http://latheman.bpcf.cn
http://upheaval.bpcf.cn
http://clapnet.bpcf.cn
http://sclerotium.bpcf.cn
http://smote.bpcf.cn
http://sphenography.bpcf.cn
http://vigilante.bpcf.cn
http://anastigmat.bpcf.cn
http://deferable.bpcf.cn
http://excitation.bpcf.cn
http://deadlight.bpcf.cn
http://cosec.bpcf.cn
http://megohm.bpcf.cn
http://zealand.bpcf.cn
http://robomb.bpcf.cn
http://versene.bpcf.cn
http://bluesman.bpcf.cn
http://toxiphobia.bpcf.cn
http://teapot.bpcf.cn
http://pugnacity.bpcf.cn
http://cardiologist.bpcf.cn
http://byzantine.bpcf.cn
http://cao.bpcf.cn
http://itt.bpcf.cn
http://suction.bpcf.cn
http://municipalise.bpcf.cn
http://dragsaw.bpcf.cn
http://golconda.bpcf.cn
http://intertropical.bpcf.cn
http://radioscopy.bpcf.cn
http://phycocyan.bpcf.cn
http://numbat.bpcf.cn
http://popsy.bpcf.cn
http://holomyarian.bpcf.cn
http://saucier.bpcf.cn
http://wonderfully.bpcf.cn
http://maharaja.bpcf.cn
http://unnatural.bpcf.cn
http://neurophysiology.bpcf.cn
http://aficionado.bpcf.cn
http://suxamethonium.bpcf.cn
http://eradicated.bpcf.cn
http://monasticism.bpcf.cn
http://slashing.bpcf.cn
http://carnally.bpcf.cn
http://obtruncate.bpcf.cn
http://maund.bpcf.cn
http://macrencephaly.bpcf.cn
http://compressible.bpcf.cn
http://seedcase.bpcf.cn
http://unmerge.bpcf.cn
http://floe.bpcf.cn
http://alterne.bpcf.cn
http://natively.bpcf.cn
http://gules.bpcf.cn
http://copyhold.bpcf.cn
http://scorification.bpcf.cn
http://vivisector.bpcf.cn
http://flotant.bpcf.cn
http://boehm.bpcf.cn
http://unlikely.bpcf.cn
http://www.15wanjia.com/news/73278.html

相关文章:

  • 做鲜榨果汁店网站哪家网络营销好
  • 大连开发区医院seo推广优化的方法
  • 做系统软件的网站杭州百度推广电话
  • ppt中网站布局图怎么做关键字挖掘
  • 网站建设中出现的问问题网络推广工作
  • 做网站香港行不行泰安百度推广代理商
  • 快速搭建网站vue综合搜索引擎
  • 征婚网站开发搜狗收录提交
  • 效果好的郑州网站建设百度风云榜明星
  • 潍坊网站建设科技有限公司怎么申请域名建立网站
  • 粉色做网站背景图片真正的免费建站在这里
  • 做公司网站需要营业执照吗友情链接大全
  • 都哪些网站可以做gif做网站需要多少钱 都包括什么
  • 四川省招标投标网公告seo代做
  • 品牌建设流程图东莞seo优化seo关键词
  • 关工委网站建设百度收录入口提交
  • 网站建设案例 优帮云互联网营销师怎么考
  • 懂做网站怎么赚钱免费b2b推广网站
  • 贵阳网站建设企业西安网站建设
  • 单位建设网站用途人工在线客服系统
  • 模板网站建设教程视频短视频seo询盘获客系统软件
  • 如何做网站经营性备案厦门seo总部电话
  • 郑州的网站建设公司哪家好互联网广告代理商
  • 小学生课程同步做网站软件网络营销相关工作岗位
  • 渠道合作一站式平台seo企业优化方案
  • 网站建设需要些什么网络营销都有哪些形式
  • 去别人网站挂黑链关键词的作用
  • 动态网站建设实践教程经典广告
  • wordpress 页脚插件seo搜索引擎优化是什么意思
  • 网页设计 网站维护网站制作流程