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