| | |
| | | |
| | | import com.yeshi.buwan.domain.SolrVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.video.AlbumVideoMap; |
| | | import com.yeshi.buwan.dto.search.SolrResultDTO; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService; |
| | | import com.yeshi.buwan.util.factory.SolrVideoFactory; |
| | | import org.apache.solr.client.solrj.response.UpdateResponse; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.solr.core.SolrTemplate; |
| | | import org.springframework.data.solr.core.query.Criteria; |
| | | import org.springframework.data.solr.core.query.Query; |
| | |
| | | |
| | | @Resource |
| | | private SolrTemplate solrTemplate; |
| | | |
| | | @Resource |
| | | private AlbumVideoMapService albumVideoMapService; |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | |
| | | public void saveOrUpdate(VideoInfo videoInfo) { |
| | |
| | | return solrVideo; |
| | | } |
| | | |
| | | public List<SolrVideo> findByKey(String key, Integer contentType, Integer videoType, int page) { |
| | | int pageSize = 20; |
| | | Query query = new SimpleQuery("name:\"" + key+"\""); |
| | | public SolrResultDTO findByKey(String key, Integer contentType, Integer videoType, int page, int pageSize) { |
| | | Query query = new SimpleQuery("name:\"" + key + "\""); |
| | | |
| | | Criteria criteria =new Criteria("contenttype").is(contentType); |
| | | Criteria criteria = new Criteria("contenttype").is(contentType); |
| | | |
| | | if (videoType != null) |
| | | criteria = criteria.and("root_video_type").is(videoType); |
| | |
| | | query.addCriteria(criteria); |
| | | |
| | | /** 设置分页开始记录数(第一页) 默认0 */ |
| | | query.setOffset((page - 1) * page); |
| | | query.setOffset((page - 1) * pageSize); |
| | | /** 设置每页显示记录数,默认10 */ |
| | | query.setRows(pageSize); |
| | | query.addSort(new Sort(Sort.Direction.DESC, "year")); |
| | | ScoredPage<SolrVideo> result = solrTemplate.queryForPage(query, SolrVideo.class); |
| | | System.out.println("总记录数:" + result.getTotalElements()); |
| | | List<SolrVideo> list = result.getContent(); |
| | | return list; |
| | | return new SolrResultDTO(list, (int) result.getTotalElements()); |
| | | } |
| | | |
| | | public List<String> getSuggestKeyList(String key) { |
| | | Query query = new SimpleQuery("name:\""+key+"\""); |
| | | Query query = new SimpleQuery("name:\"" + key + "\""); |
| | | /** 设置分页开始记录数(第一页) 默认0 */ |
| | | query.setOffset(0); |
| | | /** 设置每页显示记录数,默认10 */ |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 同步所有专辑 |
| | | */ |
| | | public void syncAllAlbum() { |
| | | long count = albumVideoMapService.countAll(); |
| | | int pageSize = 100; |
| | | int pageCount = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | for (int i = 3; i < pageCount; i++) { |
| | | List<String> videoIds = new ArrayList<>(); |
| | | List<AlbumVideoMap> albumVideoMapList = albumVideoMapService.listAll(i + 1, pageSize); |
| | | for (AlbumVideoMap map : albumVideoMapList) { |
| | | videoIds.add(map.getVideoId()); |
| | | } |
| | | List<VideoInfo> videoList = videoInfoService.listByVideoIds(videoIds); |
| | | saveOrUpdate(videoList); |
| | | } |
| | | } |
| | | |
| | | public void syncAlbum(String videoId) { |
| | | AlbumVideoMap map = albumVideoMapService.selectByVideoId(videoId); |
| | | if (map == null) |
| | | return; |
| | | |
| | | List<VideoInfo> videoList = new ArrayList<>(); |
| | | VideoInfo video = videoInfoService.getVideoInfo(videoId); |
| | | if (video != null) |
| | | videoList.add(video); |
| | | saveOrUpdate(videoList); |
| | | } |
| | | |
| | | } |