Commit de6eb9c8 by 李传峰

feat:[none] 小程序查询增加V2版本接口(搜索编辑端创建并且有资源的书)

parent b64f4f50
...@@ -28,6 +28,7 @@ import com.pcloud.book.book.constant.BookConstant; ...@@ -28,6 +28,7 @@ import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.book.dao.*; import com.pcloud.book.book.dao.*;
import com.pcloud.book.book.dto.*; import com.pcloud.book.book.dto.*;
import com.pcloud.book.book.entity.*; import com.pcloud.book.book.entity.*;
import com.pcloud.book.book.facade.impl.AppletSearchSwitchController;
import com.pcloud.book.book.set.BookSet; import com.pcloud.book.book.set.BookSet;
import com.pcloud.book.book.tools.BookTools; import com.pcloud.book.book.tools.BookTools;
import com.pcloud.book.book.vo.*; import com.pcloud.book.book.vo.*;
...@@ -2524,6 +2525,16 @@ public class BookBizImpl implements BookBiz { ...@@ -2524,6 +2525,16 @@ public class BookBizImpl implements BookBiz {
return s; return s;
} }
private Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds, Integer isAdviserBook, List<Long> adviserIds, Long agentId) {
if (AppletSearchSwitchController.useV2Search()) {
return esBookAndAdviserBiz.getESAdviserBooks4AppletV2(grayStatus, keyword, templetIds, graLabelIds, subLabelIds,
currentPage, numPerPage,scecondTempletIds, adviserIds, agentId);
} else {
return esBookAndAdviserBiz.getESAdviserBooks4Applet(grayStatus, keyword, templetIds, graLabelIds, subLabelIds,
currentPage, numPerPage,scecondTempletIds, isAdviserBook, adviserIds, agentId);
}
}
@Override @Override
public PageBeanNew<BookDto> getAdviserBooks4Applet(BookSearchParamVO bookSearchParamVO) { public PageBeanNew<BookDto> getAdviserBooks4Applet(BookSearchParamVO bookSearchParamVO) {
List<Long> templetIds = new ArrayList<>(); List<Long> templetIds = new ArrayList<>();
...@@ -2558,8 +2569,9 @@ public class BookBizImpl implements BookBiz { ...@@ -2558,8 +2569,9 @@ public class BookBizImpl implements BookBiz {
if (null != agentId) { if (null != agentId) {
adviserIds = adviserConsr.getByAgentId(agentId); adviserIds = adviserConsr.getByAgentId(agentId);
} }
Page<ESBookAndAdviser> esPage = esBookAndAdviserBiz.getESAdviserBooks4Applet(grayStatus, keyword, templetIds, graLabelIds, subLabelIds, Page<ESBookAndAdviser> esPage = getESAdviserBooks4Applet(grayStatus, keyword, templetIds, graLabelIds, subLabelIds,
currentPage, numPerPage,scecondTempletIds, isAdviserBook, adviserIds, agentId); currentPage, numPerPage,scecondTempletIds, isAdviserBook, adviserIds, agentId);
List<ESBookAndAdviser> esBookAndAdvisers = esPage.getContent(); List<ESBookAndAdviser> esBookAndAdvisers = esPage.getContent();
if (ListUtils.isEmpty(esBookAndAdvisers)) { if (ListUtils.isEmpty(esBookAndAdvisers)) {
return new PageBeanNew<>(currentPage,numPerPage,0,new ArrayList<>()); return new PageBeanNew<>(currentPage,numPerPage,0,new ArrayList<>());
......
package com.pcloud.book.book.facade.impl;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
/**
* ES同步Controller,开发人员初始化es数据使用
*/
@RestController
@RequestMapping(value = "applect/search")
public class AppletSearchSwitchController {
private static final String KEY = "applet:book:search:v2";
@GetMapping("switch")
public ResponseDto<?> use(@RequestParam("use") Boolean use,
@RequestParam("time") Integer time) {
if (Optional.ofNullable(use).orElse(false)) {
int dur = Optional.ofNullable(time).orElse(5 * 60);
JedisClusterUtils.set(KEY, "true", dur);
return new ResponseDto<>("小程序图书搜索开始使用V2版本, 时长=" + (dur / 60) + "分钟");
} else {
JedisClusterUtils.del(KEY);
return new ResponseDto<>("小程序图书搜索切回V1版本");
}
}
public static boolean useV2Search() {
return JedisClusterUtils.exists(KEY);
}
}
...@@ -20,6 +20,8 @@ public interface ESBookAndAdviserBiz { ...@@ -20,6 +20,8 @@ public interface ESBookAndAdviserBiz {
Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds, Integer isAdviserBook, List<Long> adviserIds, Long agentId); Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds, Integer isAdviserBook, List<Long> adviserIds, Long agentId);
Page<ESBookAndAdviser> getESAdviserBooks4AppletV2(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds, List<Long> adviserIds, Long agentId);
void deleteAdviserBooks4ES(); void deleteAdviserBooks4ES();
void deleteChoosedAdviserBooks4ES(String keyword); void deleteChoosedAdviserBooks4ES(String keyword);
......
...@@ -379,6 +379,66 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz { ...@@ -379,6 +379,66 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
} }
@Override @Override
public Page<ESBookAndAdviser> getESAdviserBooks4AppletV2(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds,
List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds, List<Long> adviserIds, Long agentId) {
long start = System.currentTimeMillis();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.filter(QueryBuilders.termQuery("isBookDelete", 0))
.filter(QueryBuilders.termQuery("isBookAdviserDelete", 0))
.filter(QueryBuilders.termQuery("isAdviserBook", 1))
.filter(QueryBuilders.rangeQuery("resourceCount").gt(0));
if (CollectionUtils.isNotEmpty(templetIds)) {
boolQueryBuilder.filter(QueryBuilders.termsQuery("templetId", templetIds));
}
if (agentId != null) {
boolQueryBuilder.filter(QueryBuilders.termsQuery("adviserId", adviserIds));
}
//(年级&&科目)||二级分类
BoolQueryBuilder must1 = QueryBuilders.boolQuery()
.filter(ListUtils.isEmpty(graLabelIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("graLabelId", graLabelIds))
.filter(ListUtils.isEmpty(subLabelIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("subLabelId", subLabelIds));
BoolQueryBuilder must2 = QueryBuilders.boolQuery().filter(ListUtils.isEmpty(scecondTempletIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("secondTempletId", scecondTempletIds));
BoolQueryBuilder should2 = QueryBuilders.boolQuery().should(must1).should(must2);
// 审核通过之后屏蔽掉测试编辑的书刊
BoolQueryBuilder adviserIdBuilder = getAdviserIdBuilder(grayStatus);
boolQueryBuilder.must(adviserIdBuilder);
if (isIsbn(keyword)) {
boolQueryBuilder.must(QueryBuilders.termsQuery("isbn", keyword));
} else if (StringUtils.isNotBlank(keyword)) {
MatchQueryBuilder mqb = QueryBuilders.matchQuery("ikBookName", keyword).minimumShouldMatch("75%");
boolQueryBuilder.must(mqb);
}
if (!ListUtils.isEmpty(scecondTempletIds)) {
if (ListUtils.isEmpty(graLabelIds) && ListUtils.isEmpty(subLabelIds)) {
boolQueryBuilder.must(must2);
} else {
boolQueryBuilder.must(should2);
}
} else if (!ListUtils.isEmpty(graLabelIds) || !ListUtils.isEmpty(subLabelIds)) {
boolQueryBuilder.must(must1);
}
// 排序:因为涉及分词,故而_score固定放在第一位
Sort sort = new Sort(Sort.Direction.DESC, "_score", "isApproval", "isFundSupport", "fundBookValue", "resourceCount", "isAdviserBook", "lastModifiedDate", "bookId");
if(StringUtil.isEmpty(keyword)){
sort = new Sort(Sort.Direction.DESC, "isApproval", "_score", "isFundSupport", "fundBookValue", "resourceCount", "isAdviserBook", "lastModifiedDate", "bookId");
}
PageRequest pageRequest = new PageRequest(currentPage, numPerPage, sort);
Page<ESBookAndAdviser> search = bookAndAdviserRepository.search(boolQueryBuilder, pageRequest);
log.info("es.search({})==>{},total={},cost={}",
StringUtils.replaceEach(boolQueryBuilder.toString(), new String[]{"\n", " ", " : "}, new String[]{"", "", ":"}),
search, search.getTotalElements(), (System.currentTimeMillis() - start));
return search;
}
@Override
public void deleteAdviserBooks4ES() { public void deleteAdviserBooks4ES() {
Page<ESBookAndAdviser> search = getEsBookAndAdvisers(); Page<ESBookAndAdviser> search = getEsBookAndAdvisers();
while (search.getContent().size() > 0){ while (search.getContent().size() > 0){
......
...@@ -80,5 +80,32 @@ public class ESBookAndAdviserBizTest { ...@@ -80,5 +80,32 @@ public class ESBookAndAdviserBizTest {
sw.stop(); sw.stop();
} }
@Test
public void testV2() {
StopWatch sw = new StopWatch();
sw.start();
String keyword = "语文";
Page<ESBookAndAdviser> p = esBookAndAdviserBiz.getESAdviserBooks4Applet(null,
keyword, null, null, null,
0, 100,
null, null, null, null);
log.info("key:{},count:{},cost:{},==>{}", keyword, p.getTotalElements(), sw.getTime(), StringUtils.join(IKAnalyzerUtil.analyzerText(keyword), " "));
p.forEach((baa) -> log.info(JSON.toJSONString(baa)));
sw.reset();
sw.start();
p = esBookAndAdviserBiz.getESAdviserBooks4AppletV2(null,
keyword, null, null, null,
0, 100,
null, null, null);
log.info("key:{},count:{},cost:{},==>{}", keyword, p.getTotalElements(), sw.getTime(), StringUtils.join(IKAnalyzerUtil.analyzerText(keyword), " "));
p.forEach((baa) -> log.info(JSON.toJSONString(baa)));
sw.stop();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment