diff --git a/src/main/java/com/rymcu/forest/lucene/api/LuceneSearchController.java b/src/main/java/com/rymcu/forest/lucene/api/LuceneSearchController.java index 9717152..baebd86 100755 --- a/src/main/java/com/rymcu/forest/lucene/api/LuceneSearchController.java +++ b/src/main/java/com/rymcu/forest/lucene/api/LuceneSearchController.java @@ -99,7 +99,7 @@ public class LuceneSearchController { int endIndex = Math.min(startIndex + rows, total); // 分割子列表 List subList = resList.subList(startIndex, endIndex); - String[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(String[]::new); + Long[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(Long[]::new); List articleDTOList = luceneService.getArticlesByIds(ids); ArticleDTO temp; // 写入文章关键词信息 @@ -141,7 +141,7 @@ public class LuceneSearchController { int endIndex = Math.min(startIndex + rows, total); // 分割子列表 List subList = resList.subList(startIndex, endIndex); - Integer[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Integer[]::new); + Long[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Long[]::new); List userDTOList = userLuceneService.getUsersByIds(ids); UserDTO temp; // 写入文章关键词信息 @@ -183,7 +183,7 @@ public class LuceneSearchController { int endIndex = Math.min(startIndex + rows, total); // 分割子列表 List subList = resList.subList(startIndex, endIndex); - String[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(String[]::new); + Long[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(Long[]::new); List portfolioDTOList = portfolioLuceneService.getPortfoliosByIds(ids); PortfolioDTO temp; // 写入文章关键词信息 diff --git a/src/main/java/com/rymcu/forest/lucene/mapper/ArticleLuceneMapper.java b/src/main/java/com/rymcu/forest/lucene/mapper/ArticleLuceneMapper.java index 88f3f5c..6ecb2a3 100755 --- a/src/main/java/com/rymcu/forest/lucene/mapper/ArticleLuceneMapper.java +++ b/src/main/java/com/rymcu/forest/lucene/mapper/ArticleLuceneMapper.java @@ -29,7 +29,7 @@ public interface ArticleLuceneMapper { * @param ids 文章id(半角逗号分隔) * @return */ - List getArticlesByIds(@Param("ids") String[] ids); + List getArticlesByIds(@Param("ids") Long[] ids); /** @@ -38,6 +38,6 @@ public interface ArticleLuceneMapper { * @param id 文章id * @return */ - ArticleLucene getById(@Param("id") String id); + ArticleLucene getById(@Param("id") Long id); } diff --git a/src/main/java/com/rymcu/forest/lucene/mapper/PortfolioLuceneMapper.java b/src/main/java/com/rymcu/forest/lucene/mapper/PortfolioLuceneMapper.java index cf9ac13..b75a7a4 100644 --- a/src/main/java/com/rymcu/forest/lucene/mapper/PortfolioLuceneMapper.java +++ b/src/main/java/com/rymcu/forest/lucene/mapper/PortfolioLuceneMapper.java @@ -32,7 +32,7 @@ public interface PortfolioLuceneMapper { * @param ids 作品集id(半角逗号分隔) * @return */ - List getPortfoliosByIds(@Param("ids") String[] ids); + List getPortfoliosByIds(@Param("ids") Long[] ids); /** * 加载作品集 @@ -40,5 +40,5 @@ public interface PortfolioLuceneMapper { * @param id 用户id * @return */ - PortfolioLucene getById(@Param("id") String id); + PortfolioLucene getById(@Param("id") Long id); } diff --git a/src/main/java/com/rymcu/forest/lucene/mapper/UserLuceneMapper.java b/src/main/java/com/rymcu/forest/lucene/mapper/UserLuceneMapper.java index 9e0bbf4..ad84019 100644 --- a/src/main/java/com/rymcu/forest/lucene/mapper/UserLuceneMapper.java +++ b/src/main/java/com/rymcu/forest/lucene/mapper/UserLuceneMapper.java @@ -29,7 +29,7 @@ public interface UserLuceneMapper { * @param ids 用户id(半角逗号分隔) * @return */ - List getUsersByIds(@Param("ids") Integer[] ids); + List getUsersByIds(@Param("ids") Long[] ids); /** * 加载 UserLucene diff --git a/src/main/java/com/rymcu/forest/lucene/model/ArticleLucene.java b/src/main/java/com/rymcu/forest/lucene/model/ArticleLucene.java index c8b8015..125cb11 100644 --- a/src/main/java/com/rymcu/forest/lucene/model/ArticleLucene.java +++ b/src/main/java/com/rymcu/forest/lucene/model/ArticleLucene.java @@ -1,5 +1,6 @@ package com.rymcu.forest.lucene.model; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -20,7 +21,8 @@ import javax.persistence.Id; public class ArticleLucene { /** 文章编号 */ - private String idArticle; + @JsonFormat(shape = JsonFormat.Shape.STRING) + private Long idArticle; /** 文章标题 */ private String articleTitle; diff --git a/src/main/java/com/rymcu/forest/lucene/model/PortfolioLucene.java b/src/main/java/com/rymcu/forest/lucene/model/PortfolioLucene.java index 8eabbc5..81d6b58 100644 --- a/src/main/java/com/rymcu/forest/lucene/model/PortfolioLucene.java +++ b/src/main/java/com/rymcu/forest/lucene/model/PortfolioLucene.java @@ -1,5 +1,6 @@ package com.rymcu.forest.lucene.model; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -18,7 +19,8 @@ import lombok.NoArgsConstructor; public class PortfolioLucene { /** 作品集编号 */ - private String idPortfolio; + @JsonFormat(shape = JsonFormat.Shape.STRING) + private Long idPortfolio; /** 作品集名称 */ private String portfolioTitle; diff --git a/src/main/java/com/rymcu/forest/lucene/service/LuceneService.java b/src/main/java/com/rymcu/forest/lucene/service/LuceneService.java index f83e659..6e9c6d7 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/LuceneService.java +++ b/src/main/java/com/rymcu/forest/lucene/service/LuceneService.java @@ -25,7 +25,7 @@ public interface LuceneService { * * @param id */ - void writeArticle(String id); + void writeArticle(Long id); /** @@ -40,14 +40,14 @@ public interface LuceneService { * * @param id */ - void updateArticle(String id); + void updateArticle(Long id); /** * 删除单个文章索引 * * @param id */ - void deleteArticle(String id); + void deleteArticle(Long id); /** * 关键词搜索 @@ -71,5 +71,5 @@ public interface LuceneService { * @param ids 文章id(半角逗号分隔) * @return */ - List getArticlesByIds(String[] ids); + List getArticlesByIds(Long[] ids); } diff --git a/src/main/java/com/rymcu/forest/lucene/service/PortfolioLuceneService.java b/src/main/java/com/rymcu/forest/lucene/service/PortfolioLuceneService.java index cb54e09..e532548 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/PortfolioLuceneService.java +++ b/src/main/java/com/rymcu/forest/lucene/service/PortfolioLuceneService.java @@ -25,7 +25,7 @@ public interface PortfolioLuceneService { * * @param id */ - void writePortfolio(String id); + void writePortfolio(Long id); /** * 写入单个作品集索引 @@ -39,14 +39,14 @@ public interface PortfolioLuceneService { * * @param id */ - void updatePortfolio(String id); + void updatePortfolio(Long id); /** * 删除单个作品集索引 * * @param id */ - void deletePortfolio(String id); + void deletePortfolio(Long id); /** * 关键词搜索 @@ -70,5 +70,5 @@ public interface PortfolioLuceneService { * @param ids 作品集id(半角逗号分隔) * @return */ - List getPortfoliosByIds(String[] ids); + List getPortfoliosByIds(Long[] ids); } diff --git a/src/main/java/com/rymcu/forest/lucene/service/UserLuceneService.java b/src/main/java/com/rymcu/forest/lucene/service/UserLuceneService.java index a04670e..fd2c6bd 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/UserLuceneService.java +++ b/src/main/java/com/rymcu/forest/lucene/service/UserLuceneService.java @@ -70,5 +70,5 @@ public interface UserLuceneService { * @param ids 用户id(半角逗号分隔) * @return */ - List getUsersByIds(Integer[] ids); + List getUsersByIds(Long[] ids); } diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java index 9790111..64c0bba 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java @@ -94,7 +94,7 @@ public class LuceneServiceImpl implements LuceneService { } @Override - public void writeArticle(String id) { + public void writeArticle(Long id) { writeArticle(luceneMapper.getById(id)); } @@ -104,12 +104,12 @@ public class LuceneServiceImpl implements LuceneService { } @Override - public void updateArticle(String id) { + public void updateArticle(Long id) { ArticleIndexUtil.updateIndex(luceneMapper.getById(id)); } @Override - public void deleteArticle(String id) { + public void deleteArticle(Long id) { ArticleIndexUtil.deleteIndex(id); } @@ -181,7 +181,7 @@ public class LuceneServiceImpl implements LuceneService { } resList.add( ArticleLucene.builder() - .idArticle(hitDoc.get("id")) + .idArticle(Long.valueOf(hitDoc.get("id"))) .articleTitle(titleValue.toString()) .articleContent(baikeValue.toString()) .score(String.valueOf(score)) @@ -205,9 +205,9 @@ public class LuceneServiceImpl implements LuceneService { } @Override - public List getArticlesByIds(String[] ids) { + public List getArticlesByIds(Long[] ids) { List list = luceneMapper.getArticlesByIds(ids); - list.forEach(articleDTO -> genArticle(articleDTO)); + list.forEach(this::genArticle); return list; } diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/PortfolioLuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/PortfolioLuceneServiceImpl.java index bec4e2f..964ac3c 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/PortfolioLuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/PortfolioLuceneServiceImpl.java @@ -83,7 +83,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService { } @Override - public void writePortfolio(String id) { + public void writePortfolio(Long id) { writePortfolio(portfolioLuceneMapper.getById(id)); } @@ -94,12 +94,12 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService { @Override - public void updatePortfolio(String id) { + public void updatePortfolio(Long id) { PortfolioIndexUtil.updateIndex(portfolioLuceneMapper.getById(id)); } @Override - public void deletePortfolio(String id) { + public void deletePortfolio(Long id) { PortfolioIndexUtil.deleteIndex(id); } @@ -109,7 +109,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService { } @Override - public List getPortfoliosByIds(String[] ids) { + public List getPortfoliosByIds(Long[] ids) { return portfolioLuceneMapper.getPortfoliosByIds(ids); } @@ -156,7 +156,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService { if ((textFragment != null) && (textFragment.getScore() > 0)) { // if ((frag[j] != null)) { // 获取 summary 的值 - sb.append(textFragment.toString()); + sb.append(textFragment); } } // 获取到title @@ -172,7 +172,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService { } resList.add( PortfolioLucene.builder() - .idPortfolio(hitDoc.get("id")) + .idPortfolio(Long.valueOf(hitDoc.get("id"))) .portfolioTitle(titleValue.toString()) .portfolioDescription(sb.toString()) .score(String.valueOf(score)) diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/UserLuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/UserLuceneServiceImpl.java index 4481e7f..78c8a9f 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/UserLuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/UserLuceneServiceImpl.java @@ -182,7 +182,7 @@ public class UserLuceneServiceImpl implements UserLuceneService { } @Override - public List getUsersByIds(Integer[] ids) { + public List getUsersByIds(Long[] ids) { return userLuceneMapper.getUsersByIds(ids); } } diff --git a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java index 0e6b12c..ecbf6f4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java @@ -63,7 +63,7 @@ public class ArticleIndexUtil { } /** 删除单个索引 */ - public static synchronized void deleteIndex(String id) { + public static synchronized void deleteIndex(Long id) { Arrays.stream(FileUtil.ls(PATH)) .forEach( each -> { @@ -71,7 +71,7 @@ public class ArticleIndexUtil { IndexWriter writer; try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); - writer.deleteDocuments(new Term("id", id)); + writer.deleteDocuments(new Term("id", String.valueOf(id))); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close(); diff --git a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java index 72e6589..a36cda4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java @@ -63,7 +63,7 @@ public class PortfolioIndexUtil { } /** 删除单个索引 */ - public static synchronized void deleteIndex(String id) { + public static synchronized void deleteIndex(Long id) { Arrays.stream(FileUtil.ls(PATH)) .forEach( each -> { @@ -71,7 +71,7 @@ public class PortfolioIndexUtil { IndexWriter writer; try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); - writer.deleteDocuments(new Term("id", id)); + writer.deleteDocuments(new Term("id", String.valueOf(id))); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close(); diff --git a/src/main/java/com/rymcu/forest/service/ArticleService.java b/src/main/java/com/rymcu/forest/service/ArticleService.java index 84f997f..f483229 100644 --- a/src/main/java/com/rymcu/forest/service/ArticleService.java +++ b/src/main/java/com/rymcu/forest/service/ArticleService.java @@ -82,7 +82,7 @@ public interface ArticleService extends Service
{ * @throws BaseApiException * @return */ - public String share(Integer id) throws BaseApiException; + String share(Integer id) throws BaseApiException; /** * 查询草稿文章类别 diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index 90b2c83..dc7c9ad 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -165,10 +165,10 @@ public class ArticleServiceImpl extends AbstractService
implements Arti // 草稿不更新索引 if (isUpdate) { log.info("更新文章索引,id={}", newArticleId); - luceneService.updateArticle(newArticleId.toString()); + luceneService.updateArticle(newArticleId); } else { log.info("写入文章索引,id={}", newArticleId); - luceneService.writeArticle(newArticleId.toString()); + luceneService.writeArticle(newArticleId); } // 更新文章链接 newArticle.setArticlePermalink(domain + "/article/" + newArticleId); @@ -200,9 +200,11 @@ public class ArticleServiceImpl extends AbstractService
implements Arti deleteLinkedData(id); // 删除文章 int result = articleMapper.deleteByPrimaryKey(id); - luceneService.deleteArticle(id.toString()); + luceneService.deleteArticle(id); return result; - } else throw new DataDuplicationException("已有评论的文章不允许删除!"); + } else { + throw new DataDuplicationException("已有评论的文章不允许删除!"); + } } private void deleteLinkedData(Long id) { diff --git a/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java index 8e067bd..bb6d2b7 100644 --- a/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/PortfolioServiceImpl.java @@ -80,7 +80,7 @@ public class PortfolioServiceImpl extends AbstractService implements portfolioMapper.insertSelective(portfolio); PortfolioIndexUtil.addIndex( PortfolioLucene.builder() - .idPortfolio(portfolio.getIdPortfolio().toString()) + .idPortfolio(portfolio.getIdPortfolio()) .portfolioTitle(portfolio.getPortfolioTitle()) .portfolioDescription(portfolio.getPortfolioDescription()) .build()); @@ -89,7 +89,7 @@ public class PortfolioServiceImpl extends AbstractService implements portfolioMapper.updateByPrimaryKeySelective(portfolio); PortfolioIndexUtil.updateIndex( PortfolioLucene.builder() - .idPortfolio(portfolio.getIdPortfolio().toString()) + .idPortfolio(portfolio.getIdPortfolio()) .portfolioTitle(portfolio.getPortfolioTitle()) .portfolioDescription(portfolio.getPortfolioDescription()) .build()); @@ -195,7 +195,7 @@ public class PortfolioServiceImpl extends AbstractService implements if (result.equals(0)) { map.put("message", "操作失败!"); }else { - PortfolioIndexUtil.deleteIndex(String.valueOf(idPortfolio)); + PortfolioIndexUtil.deleteIndex(idPortfolio); } } diff --git a/src/main/java/mapper/lucene/UserLuceneMapper.xml b/src/main/java/mapper/lucene/UserLuceneMapper.xml index 5c0be15..31cb8f9 100644 --- a/src/main/java/mapper/lucene/UserLuceneMapper.xml +++ b/src/main/java/mapper/lucene/UserLuceneMapper.xml @@ -36,7 +36,7 @@