网站空间送域名价格表,wordpress 页面列表显示,网站信息内容建设,大淘客 wordpress1.将用户访问记录表数据同步到ES#xff0c;并且分词#xff0c;获取用户访问最多前十条词语。
Elasticsearch、Easy-es 快速入门 SearchAfterPage分页 若依前后端分离 Ruoyi-Vue SpringBoot
使用结巴分词器 !-- 分词器--dependencygroupIdcom.hua…1.将用户访问记录表数据同步到ES并且分词获取用户访问最多前十条词语。
Elasticsearch、Easy-es 快速入门 SearchAfterPage分页 若依前后端分离 Ruoyi-Vue SpringBoot
使用结巴分词器 !-- 分词器--dependencygroupIdcom.huaban/groupIdartifactIdjieba-analysis/artifactIdversion1.0.2/version/dependency初始化数据
public void createAndInitToES() {// 1.初始化- 创建索引(相当于mysql中的表)esTzLyViewCountMapper.deleteIndex(tz_ly_view_count);esTzLyViewCountMapper.createIndex();esTzLyViewCountWordFrequencyMapper.deleteIndex(tz_ly_view_count_word);esTzLyViewCountWordFrequencyMapper.createIndex();MPJLambdaWrapperTzLyViewCount tzLyViewCountWrapper JoinWrappers.lambda(TzLyViewCount.class).selectAll(TzLyViewCount.class).selectAs(lyUser, TzLyUser::getGender, TzLyViewCount::getGender).selectAs(lyUser, TzLyUser::getEthnicity, TzLyViewCount::getEthnicity).selectAs(lyUser, TzLyUser::getPoliticalStatus, TzLyViewCount::getPoliticalStatus).selectAs(lyUser, TzLyUser::getDomain, TzLyViewCount::getDomain).selectAs(lyUser, TzLyUser::getAreaCode, TzLyViewCount::getAreaCode).leftJoin(TzLyUser.class, lyUser, on - on.eq(TzLyViewCount::getViewUserId, TzLyUser::getId));//本地限制数据大小tzLyViewCountWrapper.between(TzLyViewCount::getCreatedDate, DateUtil.parse(2024-01-01 00:00:00), DateUtil.parse(2024-02-01 00:00:00));int currentPage 1;int pageSize 1000;while (true) {PageUtils.startPage(currentPage, pageSize);ListTzLyViewCount list tzLyViewCountMapper.selectList(tzLyViewCountWrapper);// 如果当前页没有数据说明查询结束if (CollectionUtil.isEmpty(list)) {break;}EsTzLyViewCount esTzLyViewCount null;ListEsTzLyViewCount esTzLyViewCountList new ArrayList(list.size() * 2);for (TzLyViewCount viewCount : list) {esTzLyViewCount new EsTzLyViewCount();BeanUtils.copyBeanProp(esTzLyViewCount, viewCount);esTzLyViewCountList.add(esTzLyViewCount);}splitWordAndInsertEs(esTzLyViewCountList);// 准备查询下一页currentPage;}}public void splitWordAndInsertEs(ListEsTzLyViewCount esTzLyViewCountList) {JiebaSegmenter js new JiebaSegmenter();EsTzLyViewCountWord esTzLyViewCountWord null;ListEsTzLyViewCountWord esTzLyViewCountWordList new ArrayList();for (EsTzLyViewCount esTzLyViewCount : esTzLyViewCountList) {if (StringUtils.isNotBlank(esTzLyViewCount.getViewTitle())) {ListString wordList js.sentenceProcess(esTzLyViewCount.getViewTitle());for (String word : wordList) {if (word.length() 2) {esTzLyViewCountWord new EsTzLyViewCountWord();BeanUtils.copyBeanProp(esTzLyViewCountWord, esTzLyViewCount);esTzLyViewCountWord.setViewTitleWord(word);esTzLyViewCountWordList.add(esTzLyViewCountWord);}}}}esTzLyViewCountWordFrequencyMapper.insertBatch(esTzLyViewCountWordList);esTzLyViewCountMapper.insertBatch(esTzLyViewCountList);}easy-es 聚合函数 混合写法 /*** 访问信息关键词*/public ListHashMapString, Long accessInformationKeyword(StatisticsDateQueryVo statisticsDateQueryVo) {LambdaEsQueryWrapperEsTzLyViewCountWord wrapper new LambdaEsQueryWrapper();//不返回任何文档wrapper.size(0);//限制文档聚合范围if (ObjectUtils.isNotEmpty(statisticsDateQueryVo.getBgnTimestamp()) StringUtils.isNotNull(statisticsDateQueryVo.getEndTimestamp())) {Date bgnTimestamp new Date(statisticsDateQueryVo.getBgnTimestamp().getTime());Date endTimestamp new Date(statisticsDateQueryVo.getEndTimestamp().getTime());wrapper.between(EsTzLyViewCountWord::getCreatedDate, bgnTimestamp, endTimestamp);} else {// 获取当前年份假设 statisticsDateQueryVo.getQueryTimestamp() 返回的是Date类型Date queryDate statisticsDateQueryVo.getQueryTimestamp();Calendar calendar Calendar.getInstance();calendar.setTime(queryDate);int currentYear calendar.get(Calendar.YEAR);// 获取当前年份的第一天使用Calendar来设置日期部分calendar.set(Calendar.YEAR, currentYear);calendar.set(Calendar.MONTH, Calendar.JANUARY);calendar.set(Calendar.DAY_OF_MONTH, 1);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);Date firstDayOfYear calendar.getTime();// 获取当前年份的最后一天使用Calendar来设置日期部分calendar.set(Calendar.YEAR, currentYear);calendar.set(Calendar.MONTH, Calendar.DECEMBER);calendar.set(Calendar.DAY_OF_MONTH, 31);calendar.set(Calendar.HOUR_OF_DAY, 23);calendar.set(Calendar.MINUTE, 59);calendar.set(Calendar.SECOND, 59);calendar.set(Calendar.MILLISECOND, 999);Date lastDayOfYear calendar.getTime();// 设置查询条件这里的wrapper类似前面示例中的查询条件包装类需根据实际调整wrapper.between(EsTzLyViewCountWord::getCreatedDate, firstDayOfYear, lastDayOfYear);}AggregationBuilder aggregation AggregationBuilders.terms(viewTitleWordAgg)// 自定义聚合名.field(viewTitleWord) //聚合字段
// .order() 排序默认降序.size(10); //要十条记录SearchSourceBuilder searchSourceBuilder esTzLyViewCountWordFrequencyMapper.getSearchSourceBuilder(wrapper);searchSourceBuilder.aggregation(aggregation);wrapper.setSearchSourceBuilder(searchSourceBuilder);SearchResponse searchResponse esTzLyViewCountWordFrequencyMapper.search(wrapper);ListHashMapString, Long list new ArrayList();Aggregation viewTitleWordAgg searchResponse.getAggregations().getAsMap().get(viewTitleWordAgg);for (int i 0; i ((Terms) viewTitleWordAgg).getBuckets().size(); i) {Terms.Bucket bucket ((Terms) viewTitleWordAgg).getBuckets().get(i);HashMapString, Long hashMap new HashMap();hashMap.put(bucket.getKeyAsString(), bucket.getDocCount());list.add(hashMap);}return list;}
文章转载自: http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.mfmx.cn.gov.cn.mfmx.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.rjljb.cn.gov.cn.rjljb.cn http://www.morning.xhlpn.cn.gov.cn.xhlpn.cn http://www.morning.jwtwf.cn.gov.cn.jwtwf.cn http://www.morning.yydeq.cn.gov.cn.yydeq.cn http://www.morning.lyhrg.cn.gov.cn.lyhrg.cn http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn http://www.morning.frtb.cn.gov.cn.frtb.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.mfct.cn.gov.cn.mfct.cn http://www.morning.nkkr.cn.gov.cn.nkkr.cn http://www.morning.pmrlt.cn.gov.cn.pmrlt.cn http://www.morning.bswxt.cn.gov.cn.bswxt.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.rblqk.cn.gov.cn.rblqk.cn http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.lsnbx.cn.gov.cn.lsnbx.cn http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.lgwpm.cn.gov.cn.lgwpm.cn http://www.morning.cwcdr.cn.gov.cn.cwcdr.cn http://www.morning.wfkbk.cn.gov.cn.wfkbk.cn http://www.morning.ryyjw.cn.gov.cn.ryyjw.cn http://www.morning.rlqml.cn.gov.cn.rlqml.cn http://www.morning.btlsb.cn.gov.cn.btlsb.cn http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.lhgqc.cn.gov.cn.lhgqc.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.brlcj.cn.gov.cn.brlcj.cn http://www.morning.rcww.cn.gov.cn.rcww.cn http://www.morning.xxhc.cn.gov.cn.xxhc.cn http://www.morning.bscsp.cn.gov.cn.bscsp.cn http://www.morning.jxgyg.cn.gov.cn.jxgyg.cn http://www.morning.nccqs.cn.gov.cn.nccqs.cn http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn http://www.morning.wjxtq.cn.gov.cn.wjxtq.cn http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.grfhd.cn.gov.cn.grfhd.cn http://www.morning.htpjl.cn.gov.cn.htpjl.cn http://www.morning.mczjq.cn.gov.cn.mczjq.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn http://www.morning.qfmns.cn.gov.cn.qfmns.cn http://www.morning.drkk.cn.gov.cn.drkk.cn http://www.morning.xmbhc.cn.gov.cn.xmbhc.cn http://www.morning.nqgff.cn.gov.cn.nqgff.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn http://www.morning.rxhn.cn.gov.cn.rxhn.cn http://www.morning.rkmhp.cn.gov.cn.rkmhp.cn http://www.morning.qsy38.cn.gov.cn.qsy38.cn http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn http://www.morning.rnmc.cn.gov.cn.rnmc.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.mftdq.cn.gov.cn.mftdq.cn http://www.morning.rlkgc.cn.gov.cn.rlkgc.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.ymqrc.cn.gov.cn.ymqrc.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.mywmb.cn.gov.cn.mywmb.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.rwrn.cn.gov.cn.rwrn.cn http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.pgfkl.cn.gov.cn.pgfkl.cn http://www.morning.mstrb.cn.gov.cn.mstrb.cn http://www.morning.wphzr.cn.gov.cn.wphzr.cn