From f537abe9f3646c739beaf15076246a2f71a347e9 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 20 二月 2025 16:57:55 +0800 Subject: [PATCH] IOS广告增加区域屏蔽 --- src/main/java/com/yeshi/buwan/service/imp/SearchService.java | 108 ++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 76 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/SearchService.java b/src/main/java/com/yeshi/buwan/service/imp/SearchService.java index be9f7af..c76f4de 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/SearchService.java +++ b/src/main/java/com/yeshi/buwan/service/imp/SearchService.java @@ -10,10 +10,10 @@ import com.yeshi.buwan.domain.web.HotSearchAdmin; import com.yeshi.buwan.dto.search.SolrResultDTO; import com.yeshi.buwan.dto.search.SolrVideoSearchFilter; -import com.yeshi.buwan.pptv.PPTVUtil; +import com.yeshi.buwan.videos.pptv.PPTVUtil; import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; -import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager; -import com.yeshi.buwan.service.manager.SolrInternetSearchVideoDataManager; +import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager; +import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager; import com.yeshi.buwan.util.*; import com.yeshi.buwan.util.factory.VideoInfoFactory; import com.yeshi.buwan.util.video.VideoConstant; @@ -34,6 +34,9 @@ @Service public class SearchService { private Logger logger = LoggerFactory.getLogger(SearchService.class); + private Logger debugLogger = LoggerFactory.getLogger("debug"); + + private final String ALBUM_SEARCH_FUZZY_KEYS = "銆�,銆�,銆�"; @Resource @@ -288,18 +291,25 @@ } - public SearchResult searchAlbum(int videoType, String key, int page, int pageSize) { + public SearchResult searchAlbum(int videoType, String key, List<Long> resourceIds, int page, int pageSize, boolean fuzzy) { List<VideoInfo> localList = new ArrayList<>(); //涓撹緫瑙嗛闆嗗悎 Set<String> solrAlbumVids = new HashSet<>(); SolrVideoSearchFilter filter = new SolrVideoSearchFilter(); + filter.setFuzzy(fuzzy); filter.setKey(key); if (videoType == Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) { - filter.setResourceIds(new String[]{PPTVUtil.RESOURCE_ID + ""}); + filter.setResourceIds(Arrays.asList(new String[]{PPTVUtil.RESOURCE_ID + ""})); logger.info("楂樻竻鎼滅储# key锛歿}", key); - } else + } else { + List<String> rids = new ArrayList<>(); + for (Long rid : resourceIds) { + rids.add(rid + ""); + } + filter.setResourceIds(rids); filter.setVideoType(videoType == 0 ? null : videoType); + } filter.setContentType(1); SolrResultDTO solrResultDTO = solrAlbumDataManager.find(filter, page, pageSize); @@ -309,14 +319,14 @@ albumCount = solrResultDTO.getTotalCount(); for (SolrAlbumVideo sv : (List<SolrAlbumVideo>) solrResultDTO.getVideoList()) { VideoInfo video = VideoInfoFactory.create(sv); - albumSet.add(video.getName() + "#" + video.getVideoType().getId()); + albumSet.add(video.getName() + "#" + video.getVideoType().getId() + "#" + video.getYear()); video = loadAlbumData(video); localList.add(video); solrAlbumVids.add(video.getId()); } } - //绗竴椤�,涓嶄负楂樻竻,涓绘悳绱㈠紩鎿庢棤娉曟悳绱㈠埌鍐呭鏃舵悳绱� + //绗竴椤�,涓嶄负楂樻竻鏃舵悳绱� if (page == 1 && videoType != Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) { //page涓�1鏃� 鍏ㄧ綉鎼� SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, 1, 20); @@ -327,34 +337,51 @@ isvList.addAll(iList); //鍒犻櫎鍓嶉潰鏈夌殑鏁版嵁锛屾牴鎹畆ootType涓庡悕绉扮瓫閫� for (int i = 0; i < isvList.size(); i++) { - String uniqueId = isvList.get(i).getName() + "#" + isvList.get(i).getRootType(); + String uniqueId = isvList.get(i).getName() + "#" + isvList.get(i).getRootType() + "#" + isvList.get(i).getYear(); if (albumSet.contains(uniqueId)) { isvList.remove(i); i--; } } - for (InternetSearchVideo sv : isvList) { - VideoInfo video = VideoInfoFactory.create(sv); - video = loadAlbumData(video); - if (albumCount < 3) { - localList.add(video); - } else { - if (video.getName().equalsIgnoreCase(key)) + + //绮剧‘鍖归厤锛屼笉鍒嗚瘝 + if (!fuzzy) { + for (InternetSearchVideo sv : isvList) { + VideoInfo video = VideoInfoFactory.create(sv); + video = loadAlbumData(video); + //绗竴涓笓杈戞暟閲� + if (albumCount < 3) { localList.add(video); + } else { + if (video.getName().equalsIgnoreCase(key)) + localList.add(video); + } + } + } else { + for (InternetSearchVideo sv : isvList) { + VideoInfo video = VideoInfoFactory.create(sv); + video = loadAlbumData(video); + localList.add(video); } } } //鎸夊叧閿瘝鐨勫尮閰嶅害鎺掑簭 - Comparator<VideoInfo> cm = new Comparator<VideoInfo>() { - @Override - public int compare(VideoInfo o1, VideoInfo o2) { + Comparator<VideoInfo> cm = (VideoInfo o1, VideoInfo o2) -> { + if (o1.getDefinition() - o2.getDefinition() == 0) { float s1 = CompareStrSimUtil.getSimilarityRatio(o1.getName(), key, true); float s2 = CompareStrSimUtil.getSimilarityRatio(o2.getName(), key, true); - if (s1 != s2)//鐩镐技搴﹁秺楂樿秺闈犲墠 +// if (s1 != s2)//鐩镐技搴﹁秺楂樿秺闈犲墠 + try { + return s1 != s2 ? (s2 > s1 ? 1 : -1) : (Integer.parseInt(o2.getYear()) - Integer.parseInt(o1.getYear())); + } catch (Exception e) { return s2 > s1 ? 1 : -1; - else - return o1.getDefinition() - o2.getDefinition();//楂樻竻鎺掑湪鍓� + } +// else +// return o1.getDefinition() - o2.getDefinition();//楂樻竻鎺掑湪鍓� + } else { + return o2.getDefinition() - o1.getDefinition();//楂樻竻鎺掑湪鍓� } + }; Collections.sort(localList, cm); @@ -416,25 +443,35 @@ if (!StringUtil.isNullOrEmpty(key) && key.length() > 30) key = key.substring(0, 30); sh.setKey(key); - UserInfo user = new UserInfo(); - user.setId(uid); - sh.setUser(user); + if (uid != null) { + UserInfo user = new UserInfo(); + user.setId(uid); + sh.setUser(user); + } - searchDao.create(sh); +// searchDao.create(sh); // 鏌ヨ鏁版嵁搴� //涓撹緫鏁伴噺 long albumCount = 0L; List<VideoInfo> list = new ArrayList<>(); List<VideoInfo> localList = null; + long startt = System.currentTimeMillis(); try { - long startt = System.currentTimeMillis(); + localList = null; localList = new ArrayList<>(); //鍏堟悳绱笓杈� int pageSize = 20; - SearchResult searchResult = searchAlbum(videoType, key, page, pageSize); + SearchResult searchResult = searchAlbum(videoType, key, resourceList, page, pageSize, false); + + if (page == 1 && (searchResult == null || searchResult.videoInfoList == null || searchResult.videoInfoList.size() == 0)) { + searchResult = searchAlbum(videoType, key, resourceList, page, pageSize, true); + } + + debugLogger.info(String.format("鎼滅储-solr涓撹緫鎼滅储鑰楁椂锛氾紙%s锛�-%s",key,(System.currentTimeMillis() - startt))); + startt = System.currentTimeMillis(); if (searchResult != null && searchResult.videoInfoList != null) { localList.addAll(searchResult.videoInfoList); } @@ -457,11 +494,18 @@ } } } catch (Exception e) { - + debugLogger.error("甯歌鎼滅储閿欒锛歿}","",e); + }finally { + debugLogger.info(String.format("鎼滅储-solr甯歌鎼滅储鑰楁椂锛氾紙%s锛�-%s",key,(System.currentTimeMillis() - startt))); + startt = System.currentTimeMillis(); } + + } - System.out.println("鎼滅储鑰楁椂:" + (System.currentTimeMillis() - startt)); + + startt = System.currentTimeMillis(); filterSearchResult(localList, resourceList); + debugLogger.info(String.format("鎼滅储-杩囨护鑰楁椂锛氾紙%s锛�-%s",key,(System.currentTimeMillis() - startt))); } catch (Exception e) { e.printStackTrace(); } finally { @@ -469,10 +513,10 @@ if (localList != null && localList.size() > 0) { list.addAll(localList); } - + startt = System.currentTimeMillis(); //鑾峰彇闄勫姞淇℃伅 list = videoInfoExtraService.batchExtra(list, resourceList); - + debugLogger.info(String.format("鎼滅储-闄勫姞淇℃伅鑰楁椂锛氾紙%s锛�-%s",key,(System.currentTimeMillis() - startt))); return new VideoListResultVO(list, videoType == 0 ? albumCount : 1000L); } -- Gitblit v1.8.0