| | |
| | | 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.search.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager; |
| | |
| | | @Service |
| | | public class SearchService { |
| | | private Logger logger = LoggerFactory.getLogger(SearchService.class); |
| | | |
| | | private final String ALBUM_SEARCH_FUZZY_KEYS = "《,》,。"; |
| | | |
| | | |
| | | @Resource |
| | |
| | | } |
| | | |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | isvList.addAll(iList); |
| | | //删除前面有的数据,根据rootType与名称筛选 |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | float s1 = CompareStrSimUtil.getSimilarityRatio(o1.getName(), key, true); |
| | | float s2 = CompareStrSimUtil.getSimilarityRatio(o2.getName(), key, true); |
| | | // if (s1 != s2)//相似度越高越靠前 |
| | | return s2 > s1 ? 1 : -1; |
| | | 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 { |
| | |
| | | if (!StringUtil.isNullOrEmpty(key) && key.length() > 30) |
| | | key = key.substring(0, 30); |
| | | sh.setKey(key); |
| | | if(uid!=null) { |
| | | if (uid != null) { |
| | | UserInfo user = new UserInfo(); |
| | | user.setId(uid); |
| | | sh.setUser(user); |
| | |
| | | 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); |
| | | } |
| | | |
| | | if (searchResult != null && searchResult.videoInfoList != null) { |
| | | localList.addAll(searchResult.videoInfoList); |
| | | } |