mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-13 08:58:30 +00:00
索引+搜索优化
This commit is contained in:
parent
8a628f081f
commit
002a0723f7
@ -11,17 +11,20 @@ PUT /novel
|
||||
},
|
||||
"authorName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart"
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 1
|
||||
},
|
||||
|
||||
"bookName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart"
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 2
|
||||
},
|
||||
|
||||
"bookDesc" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart"
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 0.1
|
||||
},
|
||||
|
||||
"bookStatus" : {
|
||||
@ -34,7 +37,8 @@ PUT /novel
|
||||
|
||||
"catName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart"
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 0.5
|
||||
},
|
||||
|
||||
"lastIndexId" : {
|
||||
@ -43,7 +47,8 @@ PUT /novel
|
||||
|
||||
"lastIndexName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart"
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 0.1
|
||||
},
|
||||
|
||||
"lastIndexUpdateTime" : {
|
||||
|
@ -64,7 +64,7 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
/**
|
||||
* 本地图片保存路径
|
||||
* */
|
||||
*/
|
||||
@Value("${pic.save.path}")
|
||||
private String picSavePath;
|
||||
|
||||
@ -111,7 +111,7 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
/**
|
||||
* 初始化首页小说设置
|
||||
* */
|
||||
*/
|
||||
private List<BookSettingVO> initIndexBookSetting() {
|
||||
Date currentDate = new Date();
|
||||
List<Book> books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM);
|
||||
@ -185,7 +185,6 @@ public class BookServiceImpl implements BookService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public PageInfo searchByPage(BookSP params, int page, int pageSize) {
|
||||
|
||||
@ -198,6 +197,9 @@ public class BookServiceImpl implements BookService {
|
||||
}
|
||||
|
||||
if (esEnable == 1) {
|
||||
|
||||
|
||||
try {
|
||||
List<EsBookVO> bookList = new ArrayList<>(0);
|
||||
|
||||
//使用搜索引擎搜索
|
||||
@ -233,15 +235,17 @@ public class BookServiceImpl implements BookService {
|
||||
boolQueryBuilder.filter(QueryBuilders.rangeQuery("lastIndexUpdateTime").gte(params.getUpdateTimeMin()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(boolQueryBuilder);
|
||||
|
||||
|
||||
Count count = new Count.Builder().addIndex("novel").addType("book")
|
||||
.query(searchSourceBuilder.toString()).build();
|
||||
CountResult results = jestClient.execute(count);
|
||||
Double total = results.getCount();
|
||||
|
||||
// 设置高亮字段
|
||||
|
||||
// 临时屏蔽小程序未处理的高亮字段,等小程序处理后再放开
|
||||
HighlightBuilder highlightBuilder = new HighlightBuilder();
|
||||
@ -251,9 +255,10 @@ public class BookServiceImpl implements BookService {
|
||||
highlightBuilder.field("lastIndexName");
|
||||
highlightBuilder.field("catName");
|
||||
highlightBuilder.preTags("<span style='color:red'>").postTags("</span>");
|
||||
highlightBuilder.fragmentSize(200);
|
||||
highlightBuilder.fragmentSize(20000);
|
||||
searchSourceBuilder.highlighter(highlightBuilder);
|
||||
|
||||
|
||||
//设置排序
|
||||
if (params.getSort() != null) {
|
||||
searchSourceBuilder.sort(StringUtil.camelName(params.getSort()), SortOrder.DESC);
|
||||
@ -268,6 +273,7 @@ public class BookServiceImpl implements BookService {
|
||||
log.debug(search.toString());
|
||||
SearchResult result;
|
||||
result = jestClient.execute(search);
|
||||
if (result.isSucceeded()) {
|
||||
log.debug(result.getJsonString());
|
||||
|
||||
Map resultMap = new ObjectMapper().readValue(result.getJsonString(), Map.class);
|
||||
@ -316,7 +322,6 @@ public class BookServiceImpl implements BookService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,19 +332,19 @@ public class BookServiceImpl implements BookService {
|
||||
pageInfo.setPageNum(page);
|
||||
pageInfo.setPageSize(pageSize);
|
||||
return pageInfo;
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
}
|
||||
PageHelper.startPage(page, pageSize);
|
||||
|
||||
if (StringUtils.isNotBlank(params.getSort())) {
|
||||
OrderByHelper.orderBy(params.getSort() + " desc");
|
||||
}
|
||||
return new PageInfo<>(bookMapper.searchByPage(params));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -567,7 +572,6 @@ public class BookServiceImpl implements BookService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Long queryIdByNameAndAuthor(String bookName, String author) {
|
||||
//查询小说ID
|
||||
@ -637,7 +641,8 @@ public class BookServiceImpl implements BookService {
|
||||
if (queryIdByNameAndAuthor(book.getBookName(), penName) != null) {
|
||||
//该作者发布过此书名的小说
|
||||
throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS);
|
||||
};
|
||||
}
|
||||
;
|
||||
book.setAuthorName(penName);
|
||||
book.setAuthorId(authorId);
|
||||
book.setVisitCount(0L);
|
||||
@ -711,7 +716,6 @@ public class BookServiceImpl implements BookService {
|
||||
bookContentMapper.insertSelective(bookContent);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,7 +11,7 @@ spring:
|
||||
#是否开启搜索引擎,1:开启,0:不开启
|
||||
enable: 0
|
||||
jest:
|
||||
uris: http://198.245.61.51:9200
|
||||
uris: http://127.0.0.1:9200
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user