Multisim14.0界面详解:入门必看的五大核心区域解析

核心内容摘要

AI辅助开发实战:使用Cherry Studio高效部署火山引擎应用
基于STC89C52单片机的智能窗帘控制系统设计

车牌检测实战:从数据集准备到YOLO模型训练全流程解析

前言要实现按天创建索引如article_20250906的需求我们需要通过 Easy-Es 的索引名称处理器来动态生成索引名。

以下是具体实现方案

自定义索引名称处理器packagecom.zgb.config;importorg.dromara.easyes.core.handler.IndexNameHandler;importjava.time.LocalDate;importjava.time.format.DateTimeFormatter;/** * 文章索引名称处理器 * 实现按天动态生成索引名格式为: article_yyyyMMdd * author 架构师 */publicclassArticleIndexNameHandlerimplementsIndexNameHandler{/** * 动态生成索引名称 * return 格式化后的索引名称 */OverridepublicStringdynamicIndexName(){// 获取当前日期并格式化为yyyyMMddStringdateSuffixLocalDate.now().format(DateTimeFormatter.ofPattern(yyyyMMdd));// 返回拼接后的索引名returnarticle_dateSuffix;}}

修改实体类的索引配置在你提供的Article实体类上添加动态索引处理器配置packagecom.zgb.entity;importcom.fasterxml.jackson.annotation.JsonFormat;importcom.zgb.config.ArticleIndexNameHandler;importlombok.Data;importorg.dromara.easyes.annotation.*;importorg.dromara.easyes.annotation.rely.FieldType;importjava.time.LocalDateTime;importjava.util.List;/** * 文章索引实体类 * 按天创建索引格式为article_yyyyMMdd * author 架构师 */DataIndexName(valuearticle,// 基础索引名dynamicIndexHandlerArticleIndexNameHandler.class,// 指定动态索引处理器keepGlobalPrefixfalse// 不保留全局前缀使用处理器生成的完整名称)publicclassArticle{/** * 文章ID */IdprivateStringid;/** * 文章标题 * 分词,可搜索,权重较高 */HighLight(mappingFieldtitleHighLight)// 高亮配置IndexField(fieldTypeFieldType.TEXT,analyzerik_max_word,searchAnalyzerik_smart,boost

0f)privateStringtitle;/** * 标题高亮结果 */privateStringtitleHighLight;/** * 文章内容 * 分词,可搜索 */HighLight(mappingFieldcontentHighLight)IndexField(fieldTypeFieldType.TEXT,analyzerik_max_word,searchAnalyzerik_smart)privateStringcontent;/** * 内容高亮结果 */privateStringcontentHighLight;/** * 文章摘要 */IndexField(fieldTypeFieldType.TEXT,analyzerik_max_word)privateStringsummary;/** * 文章作者 */IndexField(fieldTypeFieldType.KEYWORD)privateStringauthor;/** * 创建时间 */IndexField(fieldTypeFieldType.DATE,dateFormatyyyy-MM-dd HH:mm:ss)JsonFormat(patternyyyy-MM-dd HH:mm:ss,timezoneGMT

privateLocalDateTimecreateTime;/** * 文章类型 * 如: 原创、转载、翻译 */IndexField(fieldTypeFieldType.KEYWORD)privateStringtype;/** * 文章标签 */IndexField(fieldTypeFieldType.KEYWORD)privateListStringtags;/** * 点赞数 */IndexField(fieldTypeFieldType.INTEGER)privateIntegerlikeCount;/** * 分享数 */IndexField(fieldTypeFieldType.INTEGER)privateIntegershareCount;/** * 预览数 */IndexField(fieldTypeFieldType.INTEGER)privateIntegerviewCount;}

配置文件调整spring:easy-es:enable:trueaddress:

127.

0.

1:9200# 单机版配置分布式版使用逗号分隔多个地址username:elasticpassword:123456connection-timeout:5000socket-timeout:30000global-config:process-index-name:false# 关闭全局处理由自定义处理器接管db-config:id-type:custom# 自定义ID生成策略# 不设置table-prefix避免与动态索引名冲突

索引管理工具类packagecom.zgb.util;importcom.zgb.entity.Article;importorg.dromara.easyes.core.biz.EsIndexParam;importorg.dromara.easyes.core.manager.IndexManager;importorg.springframework.stereotype.Component;importjavax.annotation.Resource;importjava.time.LocalDate;importjava.time.format.DateTimeFormatter;/** * 文章索引管理工具类 * 用于创建和管理按天分割的文章索引 * author 架构师 */ComponentpublicclassArticleIndexManager{ResourceprivateIndexManagerindexManager;/** * 创建指定日期的文章索引 * param date 指定日期 * return 是否创建成功 */publicbooleancreateIndex(LocalDatedate){StringindexNamearticle_date.format(DateTimeFormatter.ofPattern(yyyyMMdd));// 构建索引参数使用提供的Article实体类EsIndexParamesIndexParamEsIndexParam.builder().indexName(indexName).clazz(Article.class)// 关联实体类确保映射关系正确.build();// 创建索引returnindexManager.createIndex(esIndexParam);}/** * 创建今天的文章索引 * return 是否创建成功 */publicbooleancreateTodayIndex(){returncreateIndex(LocalDate.now());}/** * 删除指定日期的文章索引 * param date 指定日期 * return 是否删除成功 */publicbooleandeleteIndex(LocalDatedate){StringindexNamearticle_date.format(DateTimeFormatter.ofPattern(yyyyMMdd));returnindexManager.deleteIndex(indexName);}/** * 判断指定日期的索引是否存在 * param date 指定日期 * return 是否存在 */publicbooleanexistsIndex(LocalDatedate){StringindexNamearticle_date.format(DateTimeFormatter.ofPattern(yyyyMMdd));returnindexManager.existsIndex(indexName);}}

定时任务自动创建索引 IndexAutoCreateTaskpackagecom.zgb.task;importcom.zgb.util.ArticleIndexManager;importlombok.RequiredArgsConstructor;importorg.springframework.scheduling.annotation.Scheduled;importorg.springframework.stereotype.Component;/** * 索引自动创建定时任务 * 确保每天都有对应的索引可用 * author 架构师 */ComponentRequiredArgsConstructorpublicclassIndexAutoCreateTask{privatefinalArticleIndexManagerindexManager;/** * 每天凌晨1点创建当天的索引 * 防止当天第一次插入数据时才创建索引可能带来的性能问题 */Scheduled(cron0 0 1 * * ?)publicvoidcreateTodayIndex(){// 先判断索引是否已存在避免重复创建if(!indexManager.existsIndex(LocalDate.now())){booleanresultindexManager.createTodayIndex();if(result){System.out.println(成功创建当天文章索引: article_LocalDate.now().format(DateTimeFormatter.ofPattern(yyyyMMdd)));}else{System.err.println(创建当天文章索引失败);}}}}

按日期范围查询的Service实现/** * 按日期范围查询文章 * param keyword 搜索关键词 * param startDate 开始日期 * param endDate 结束日期 * param pageNum 页码 * param pageSize 每页条数 * return 分页结果 */publicPageInfoArticlesearchByDateRange(Stringkeyword,LocalDatestartDate,LocalDateendDate,IntegerpageNum,IntegerpageSize){// 构建查询条件LambdaEsQueryWrapperArticlewrappernewLambdaEsQueryWrapper();// 设置关键词匹配标题、内容或摘要if(keyword!null!keyword.isEmpty()){wrapper.match(Article::getTitle,keyword).or().match(Article::getContent,keyword).or().match(Article::getSummary,keyword);}// 处理日期范围索引查询if(startDate!nullendDate!null){// 构建索引名称通配符StringstartMonthstartDate.format(DateTimeFormatter.ofPattern(yyyyMM));StringendMonthendDate.format(DateTimeFormatter.ofPattern(yyyyMM));if(startMonth.equals(endMonth)){// 同一月份使用更精确的通配符wrapper.index(article_startMonth*);}else{// 跨月份使用年份通配符StringyearstartDate.format(DateTimeFormatter.ofPattern(yyyy));wrapper.index(article_year*);}// 同时添加创建时间过滤确保数据准确性wrapper.ge(Article::getCreateTime,startDate.atStartOfDay()).le(Article::getCreateTime,endDate.atTime(23,59,

);}elseif(startDate!null){// 只指定开始日期wrapper.index(article_startDate.format(DateTimeFormatter.ofPattern(yyyyMM))*).ge(Article::getCreateTime,startDate.atStartOfDay());}elseif(endDate!null){// 只指定结束日期wrapper.index(article_endDate.format(DateTimeFormatter.ofPattern(yyyyMM))*).le(Article::getCreateTime,endDate.atTime(23,59,

);}// 按点赞数和创建时间排序wrapper.orderByDesc(Article::getLikeCount).orderByDesc(Article::getCreateTime);// 执行查询returnarticleEsMapper.pageQuery(wrapper,pageNum,pageSize);}实现说明索引动态生成通过ArticleIndexNameHandler实现了按天生成索引名的功能与你提供的Article实体类完美结合索引管理工具类ArticleIndexManager专门用于管理按天创建的索引定时任务确保每天凌晨自动创建当天索引避免业务高峰期创建索引影响性能查询优化单天查询自动使用当天索引如article_20250906跨天查询使用通配符匹配多个索引并结合创建时间过滤保证数据准确性保持了原有实体类的所有字段和注解配置不影响原有的搜索功能这种实现方式既满足了按天分割索引的需求又完整保留了你提供的Article实体类的所有特性包括字段映射、分词策略和高亮配置等。

两人做aj的视频教程大全免费观看-两人做aj的视频教程大全免费观看应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123