| | |
| | | @Service |
| | | public class SearchService { |
| | | private Logger logger = LoggerFactory.getLogger(SearchService.class); |
| | | private Logger debugLogger = LoggerFactory.getLogger("debug"); |
| | | |
| | | private final String ALBUM_SEARCH_FUZZY_KEYS = "《,》,。"; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | public SearchResult searchAlbum(int videoType, String key, List<Long> resourceIds, 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(Arrays.asList(new String[]{PPTVUtil.RESOURCE_ID + ""})); |
| | | logger.info("高清搜索# key:{}", key); |
| | | } else { |
| | | |
| | | List<String> rids = new ArrayList<>(); |
| | | for (Long rid : resourceIds) { |
| | | rids.add(rid + ""); |
| | |
| | | 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()); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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, resourceList, 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); |
| | | } |
| | |
| | | } |
| | | } |
| | | } 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 { |
| | |
| | | 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); |
| | | } |
| | | |