Merge remote-tracking branch 'origin/lucene-dev' into lucene-dev

This commit is contained in:
ronger 2021-05-21 15:53:35 +08:00
commit 9ea0761a92
3 changed files with 162 additions and 156 deletions

View File

@ -38,10 +38,14 @@ import java.util.concurrent.Executors;
@RequestMapping("/api/v1/lucene")
public class LuceneSearchController {
@Resource private LuceneService luceneService;
@Resource private UserLuceneService userLuceneService;
@Resource private PortfolioLuceneService portfolioLuceneService;
@Resource private UserDicService dicService;
@Resource
private LuceneService luceneService;
@Resource
private UserLuceneService userLuceneService;
@Resource
private PortfolioLuceneService portfolioLuceneService;
@Resource
private UserDicService dicService;
@PostConstruct
public void createIndex() {
@ -77,11 +81,11 @@ public class LuceneSearchController {
* @param q
* @return
*/
@GetMapping("/searchArticle/{q}")
@GetMapping("/search-article")
public GlobalResult<?> searchArticle(
@PathVariable String q,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
@RequestParam String q,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer rows) {
// 找出相关文章相关度倒序
List<ArticleLucene> resList = luceneService.searchArticle(q);
// 分页组装文章详情
@ -89,10 +93,10 @@ public class LuceneSearchController {
if (total == 0) {
return GlobalResultGenerator.genSuccessResult("未找到相关文章");
}
Page<ArticleDTO> page = new Page<>(pageNum, pageSize);
page.setTotal(total);
int startIndex = (pageNum - 1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, total);
Page<ArticleDTO> articles = new Page<>(page, rows);
articles.setTotal(total);
int startIndex = (page - 1) * rows;
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<ArticleLucene> subList = resList.subList(startIndex, endIndex);
String[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(String[]::new);
@ -108,8 +112,8 @@ public class LuceneSearchController {
}
articleDTOList.set(i, temp);
}
page.addAll(articleDTOList);
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(page);
articles.addAll(articleDTOList);
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(articles);
return GlobalResultGenerator.genSuccessResult(Utils.getArticlesGlobalResult(pageInfo));
}
@ -119,11 +123,11 @@ public class LuceneSearchController {
* @param q
* @return
*/
@GetMapping("/searchUser/{q}")
@GetMapping("/search-user")
public GlobalResult<?> searchUser(
@PathVariable String q,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
@RequestParam String q,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer rows) {
// 找出相关文章相关度倒序
List<UserLucene> resList = userLuceneService.searchUser(q);
// 分页组装文章详情
@ -131,10 +135,10 @@ public class LuceneSearchController {
if (total == 0) {
return GlobalResultGenerator.genSuccessResult("未找到相关用户");
}
Page<UserDTO> page = new Page<>(pageNum, pageSize);
page.setTotal(total);
int startIndex = (pageNum - 1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, total);
Page<UserDTO> users = new Page<>(page, rows);
users.setTotal(total);
int startIndex = (page - 1) * rows;
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<UserLucene> subList = resList.subList(startIndex, endIndex);
Integer[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Integer[]::new);
@ -150,8 +154,8 @@ public class LuceneSearchController {
}
userDTOList.set(i, temp);
}
page.addAll(userDTOList);
PageInfo<UserDTO> pageInfo = new PageInfo<>(page);
users.addAll(userDTOList);
PageInfo<UserDTO> pageInfo = new PageInfo<>(users);
return GlobalResultGenerator.genSuccessResult(Utils.getUserGlobalResult(pageInfo));
}
@ -161,11 +165,11 @@ public class LuceneSearchController {
* @param q
* @return
*/
@GetMapping("/searchPortfolio/{q}")
@GetMapping("/search-portfolio")
public GlobalResult<?> searchPortfolio(
@PathVariable String q,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
@RequestParam String q,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer rows) {
// 找出相关文章相关度倒序
List<PortfolioLucene> resList = portfolioLuceneService.searchPortfolio(q);
// 分页组装文章详情
@ -173,10 +177,10 @@ public class LuceneSearchController {
if (total == 0) {
return GlobalResultGenerator.genSuccessResult("未找到相关作品集");
}
Page<PortfolioDTO> page = new Page<>(pageNum, pageSize);
page.setTotal(total);
int startIndex = (pageNum - 1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, total);
Page<PortfolioDTO> portfolios = new Page<>(page, rows);
portfolios.setTotal(total);
int startIndex = (page - 1) * rows;
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<PortfolioLucene> subList = resList.subList(startIndex, endIndex);
String[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(String[]::new);
@ -192,8 +196,8 @@ public class LuceneSearchController {
}
portfolioDTOList.set(i, temp);
}
page.addAll(portfolioDTOList);
PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(page);
portfolios.addAll(portfolioDTOList);
PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(portfolios);
return GlobalResultGenerator.genSuccessResult(Utils.getPortfolioGlobalResult(pageInfo));
}
}

View File

@ -28,9 +28,9 @@ public class UserDicController {
@GetMapping("/getAll")
public GlobalResult getAll(
@RequestParam(defaultValue = "0") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows);
List<UserDic> list = dicService.getAll();
PageInfo<UserDic> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2);

View File

@ -34,7 +34,8 @@
<select id="getAllArticleLucene" resultMap="ResultMapWithBLOBs">
select art.id, art.article_title, content.article_content
from forest_article art
join forest_article_content content on art.id = content.id_article;
join forest_article_content content on art.id = content.id_article
where article_status = 0;
</select>
<select id="getArticlesByIds" resultMap="DTOResultMap">
@ -59,6 +60,7 @@
select art.id, art.article_title, content.article_content
from forest_article art
join forest_article_content content on art.id = content.id_article
where id = #{id};
where article_status = 0
and id = #{id};
</select>
</mapper>