Merge remote-tracking branch 'origin/lucene-dev' into lucene-dev
This commit is contained in:
commit
9ea0761a92
@ -38,162 +38,166 @@ 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() {
|
||||||
// 删除系统运行时保存的索引,重新创建索引
|
// 删除系统运行时保存的索引,重新创建索引
|
||||||
ArticleIndexUtil.deleteAllIndex();
|
ArticleIndexUtil.deleteAllIndex();
|
||||||
UserIndexUtil.deleteAllIndex();
|
UserIndexUtil.deleteAllIndex();
|
||||||
PortfolioIndexUtil.deleteAllIndex();
|
PortfolioIndexUtil.deleteAllIndex();
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
CompletableFuture<String> future =
|
CompletableFuture<String> future =
|
||||||
CompletableFuture.supplyAsync(
|
CompletableFuture.supplyAsync(
|
||||||
() -> {
|
() -> {
|
||||||
System.out.println(">>>>>>>>> 开始创建索引 <<<<<<<<<<<");
|
System.out.println(">>>>>>>>> 开始创建索引 <<<<<<<<<<<");
|
||||||
luceneService.writeArticle(luceneService.getAllArticleLucene());
|
luceneService.writeArticle(luceneService.getAllArticleLucene());
|
||||||
userLuceneService.writeUser(userLuceneService.getAllUserLucene());
|
userLuceneService.writeUser(userLuceneService.getAllUserLucene());
|
||||||
portfolioLuceneService.writePortfolio(portfolioLuceneService.getAllPortfolioLucene());
|
portfolioLuceneService.writePortfolio(portfolioLuceneService.getAllPortfolioLucene());
|
||||||
System.out.println(">>>>>>>>> 索引创建完毕 <<<<<<<<<<<");
|
System.out.println(">>>>>>>>> 索引创建完毕 <<<<<<<<<<<");
|
||||||
System.out.println("加载用户配置的自定义扩展词典到主词库表");
|
System.out.println("加载用户配置的自定义扩展词典到主词库表");
|
||||||
try {
|
try {
|
||||||
System.out.println(">>>>>>>>> 开始加载用户词典 <<<<<<<<<<<");
|
System.out.println(">>>>>>>>> 开始加载用户词典 <<<<<<<<<<<");
|
||||||
dicService.writeUserDic();
|
dicService.writeUserDic();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("加载用户词典失败,未成功创建用户词典");
|
System.out.println("加载用户词典失败,未成功创建用户词典");
|
||||||
}
|
}
|
||||||
return ">>>>>>>>> 加载用户词典完毕 <<<<<<<<<<<";
|
return ">>>>>>>>> 加载用户词典完毕 <<<<<<<<<<<";
|
||||||
},
|
},
|
||||||
executor);
|
executor);
|
||||||
future.thenAccept(System.out::println);
|
future.thenAccept(System.out::println);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章搜索,实现高亮
|
* 文章搜索,实现高亮
|
||||||
*
|
*
|
||||||
* @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);
|
||||||
// 分页组装文章详情
|
// 分页组装文章详情
|
||||||
int total = resList.size();
|
int total = resList.size();
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return GlobalResultGenerator.genSuccessResult("未找到相关文章");
|
return GlobalResultGenerator.genSuccessResult("未找到相关文章");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
List<ArticleDTO> articleDTOList = luceneService.getArticlesByIds(ids);
|
||||||
|
ArticleDTO temp;
|
||||||
|
// 写入文章关键词信息
|
||||||
|
for (int i = 0; i < articleDTOList.size(); i++) {
|
||||||
|
temp = articleDTOList.get(i);
|
||||||
|
temp.setArticleTitle(subList.get(i).getArticleTitle());
|
||||||
|
if (subList.get(i).getArticleContent().length() > 10) {
|
||||||
|
// 内容中命中太少则不替换
|
||||||
|
temp.setArticlePreviewContent(subList.get(i).getArticleContent());
|
||||||
|
}
|
||||||
|
articleDTOList.set(i, temp);
|
||||||
|
}
|
||||||
|
articles.addAll(articleDTOList);
|
||||||
|
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(articles);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(Utils.getArticlesGlobalResult(pageInfo));
|
||||||
}
|
}
|
||||||
Page<ArticleDTO> page = new Page<>(pageNum, pageSize);
|
|
||||||
page.setTotal(total);
|
|
||||||
int startIndex = (pageNum - 1) * pageSize;
|
|
||||||
int endIndex = Math.min(startIndex + pageSize, total);
|
|
||||||
// 分割子列表
|
|
||||||
List<ArticleLucene> subList = resList.subList(startIndex, endIndex);
|
|
||||||
String[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(String[]::new);
|
|
||||||
List<ArticleDTO> articleDTOList = luceneService.getArticlesByIds(ids);
|
|
||||||
ArticleDTO temp;
|
|
||||||
// 写入文章关键词信息
|
|
||||||
for (int i = 0; i < articleDTOList.size(); i++) {
|
|
||||||
temp = articleDTOList.get(i);
|
|
||||||
temp.setArticleTitle(subList.get(i).getArticleTitle());
|
|
||||||
if (subList.get(i).getArticleContent().length() > 10) {
|
|
||||||
// 内容中命中太少则不替换
|
|
||||||
temp.setArticlePreviewContent(subList.get(i).getArticleContent());
|
|
||||||
}
|
|
||||||
articleDTOList.set(i, temp);
|
|
||||||
}
|
|
||||||
page.addAll(articleDTOList);
|
|
||||||
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(page);
|
|
||||||
return GlobalResultGenerator.genSuccessResult(Utils.getArticlesGlobalResult(pageInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户搜索,实现高亮
|
* 用户搜索,实现高亮
|
||||||
*
|
*
|
||||||
* @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);
|
||||||
// 分页组装文章详情
|
// 分页组装文章详情
|
||||||
int total = resList.size();
|
int total = resList.size();
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return GlobalResultGenerator.genSuccessResult("未找到相关用户");
|
return GlobalResultGenerator.genSuccessResult("未找到相关用户");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
List<UserDTO> userDTOList = userLuceneService.getUsersByIds(ids);
|
||||||
|
UserDTO temp;
|
||||||
|
// 写入文章关键词信息
|
||||||
|
for (int i = 0; i < userDTOList.size(); i++) {
|
||||||
|
temp = userDTOList.get(i);
|
||||||
|
temp.setNickname(subList.get(i).getNickname());
|
||||||
|
if (subList.get(i).getSignature().length() > 10) {
|
||||||
|
// 内容中命中太少则不替换
|
||||||
|
temp.setSignature(subList.get(i).getSignature());
|
||||||
|
}
|
||||||
|
userDTOList.set(i, temp);
|
||||||
|
}
|
||||||
|
users.addAll(userDTOList);
|
||||||
|
PageInfo<UserDTO> pageInfo = new PageInfo<>(users);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(Utils.getUserGlobalResult(pageInfo));
|
||||||
}
|
}
|
||||||
Page<UserDTO> page = new Page<>(pageNum, pageSize);
|
|
||||||
page.setTotal(total);
|
|
||||||
int startIndex = (pageNum - 1) * pageSize;
|
|
||||||
int endIndex = Math.min(startIndex + pageSize, total);
|
|
||||||
// 分割子列表
|
|
||||||
List<UserLucene> subList = resList.subList(startIndex, endIndex);
|
|
||||||
Integer[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Integer[]::new);
|
|
||||||
List<UserDTO> userDTOList = userLuceneService.getUsersByIds(ids);
|
|
||||||
UserDTO temp;
|
|
||||||
// 写入文章关键词信息
|
|
||||||
for (int i = 0; i < userDTOList.size(); i++) {
|
|
||||||
temp = userDTOList.get(i);
|
|
||||||
temp.setNickname(subList.get(i).getNickname());
|
|
||||||
if (subList.get(i).getSignature().length() > 10) {
|
|
||||||
// 内容中命中太少则不替换
|
|
||||||
temp.setSignature(subList.get(i).getSignature());
|
|
||||||
}
|
|
||||||
userDTOList.set(i, temp);
|
|
||||||
}
|
|
||||||
page.addAll(userDTOList);
|
|
||||||
PageInfo<UserDTO> pageInfo = new PageInfo<>(page);
|
|
||||||
return GlobalResultGenerator.genSuccessResult(Utils.getUserGlobalResult(pageInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作品集搜索,实现高亮
|
* 作品集搜索,实现高亮
|
||||||
*
|
*
|
||||||
* @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);
|
||||||
// 分页组装文章详情
|
// 分页组装文章详情
|
||||||
int total = resList.size();
|
int total = resList.size();
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return GlobalResultGenerator.genSuccessResult("未找到相关作品集");
|
return GlobalResultGenerator.genSuccessResult("未找到相关作品集");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
List<PortfolioDTO> portfolioDTOList = portfolioLuceneService.getPortfoliosByIds(ids);
|
||||||
|
PortfolioDTO temp;
|
||||||
|
// 写入文章关键词信息
|
||||||
|
for (int i = 0; i < portfolioDTOList.size(); i++) {
|
||||||
|
temp = portfolioDTOList.get(i);
|
||||||
|
temp.setPortfolioTitle(subList.get(i).getPortfolioTitle());
|
||||||
|
if (subList.get(i).getPortfolioDescription().length() > 10) {
|
||||||
|
// 内容中命中太少则不替换
|
||||||
|
temp.setPortfolioDescription(subList.get(i).getPortfolioDescription());
|
||||||
|
}
|
||||||
|
portfolioDTOList.set(i, temp);
|
||||||
|
}
|
||||||
|
portfolios.addAll(portfolioDTOList);
|
||||||
|
PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(portfolios);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(Utils.getPortfolioGlobalResult(pageInfo));
|
||||||
}
|
}
|
||||||
Page<PortfolioDTO> page = new Page<>(pageNum, pageSize);
|
|
||||||
page.setTotal(total);
|
|
||||||
int startIndex = (pageNum - 1) * pageSize;
|
|
||||||
int endIndex = Math.min(startIndex + pageSize, total);
|
|
||||||
// 分割子列表
|
|
||||||
List<PortfolioLucene> subList = resList.subList(startIndex, endIndex);
|
|
||||||
String[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(String[]::new);
|
|
||||||
List<PortfolioDTO> portfolioDTOList = portfolioLuceneService.getPortfoliosByIds(ids);
|
|
||||||
PortfolioDTO temp;
|
|
||||||
// 写入文章关键词信息
|
|
||||||
for (int i = 0; i < portfolioDTOList.size(); i++) {
|
|
||||||
temp = portfolioDTOList.get(i);
|
|
||||||
temp.setPortfolioTitle(subList.get(i).getPortfolioTitle());
|
|
||||||
if (subList.get(i).getPortfolioDescription().length() > 10) {
|
|
||||||
// 内容中命中太少则不替换
|
|
||||||
temp.setPortfolioDescription(subList.get(i).getPortfolioDescription());
|
|
||||||
}
|
|
||||||
portfolioDTOList.set(i, temp);
|
|
||||||
}
|
|
||||||
page.addAll(portfolioDTOList);
|
|
||||||
PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(page);
|
|
||||||
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);
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
<select id="getAllArticleLucene" resultMap="ResultMapWithBLOBs">
|
<select id="getAllArticleLucene" resultMap="ResultMapWithBLOBs">
|
||||||
select art.id, art.article_title, content.article_content
|
select art.id, art.article_title, content.article_content
|
||||||
from forest_article art
|
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>
|
||||||
|
|
||||||
<select id="getArticlesByIds" resultMap="DTOResultMap">
|
<select id="getArticlesByIds" resultMap="DTOResultMap">
|
||||||
@ -59,6 +60,7 @@
|
|||||||
select art.id, art.article_title, content.article_content
|
select art.id, art.article_title, content.article_content
|
||||||
from forest_article art
|
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 id = #{id};
|
where article_status = 0
|
||||||
|
and id = #{id};
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
Reference in New Issue
Block a user