| | |
| | | package com.yeshi.buwan.service.manager.search; |
| | | |
| | | import com.yeshi.buwan.domain.HomeVideo; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.domain.entity.PlayUrl; |
| | | import com.yeshi.buwan.domain.solr.SolrShortVideo; |
| | | import com.yeshi.buwan.dto.search.SolrResultDTO; |
| | | import com.yeshi.buwan.dto.search.SolrShortVideoSearchFilter; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.video.VideoUtil; |
| | | import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2; |
| | | import org.apache.solr.client.solrj.response.UpdateResponse; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | /** |
| | | * 删除所有 |
| | | */ |
| | | // public void clear() { |
| | | // Query query = new SimpleQuery("name:*"); |
| | | // UpdateResponse updateResponse = solrTemplate.delete(query); |
| | | // if (updateResponse.getStatus() == 0) { |
| | | // solrTemplate.commit(); |
| | | // } else { |
| | | // solrTemplate.rollback(); |
| | | // } |
| | | // } |
| | | public void clear() { |
| | | Query query = new SimpleQuery("name:*"); |
| | | UpdateResponse updateResponse = solrTemplate.delete(query); |
| | | if (updateResponse.getStatus() == 0) { |
| | | solrTemplate.commit(); |
| | | } else { |
| | | solrTemplate.rollback(); |
| | | } |
| | | } |
| | | |
| | | public void deleteById(String id) { |
| | | UpdateResponse updateResponse = solrTemplate.deleteById(CORE_NAME, id); |
| | | if (updateResponse.getStatus() == 0) { |
| | |
| | | } |
| | | |
| | | public SolrShortVideo findOne(String id) { |
| | | SolrShortVideo solrVideo = solrTemplate.getById(CORE_NAME, id, SolrShortVideo.class); |
| | | return solrVideo; |
| | | Query query = new SimpleQuery(new Criteria("id").is(id)); |
| | | ScoredPage<SolrShortVideo> result = solrTemplate.queryForPage(CORE_NAME, query, SolrShortVideo.class); |
| | | if (result != null && result.getContent().size() > 0) { |
| | | return result.getContent().get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public SolrResultDTO find(SolrShortVideoSearchFilter filter, int page, int pageSize) { |
| | |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("root_video_type").is(filter.getRootVideoType()))); |
| | | } |
| | | |
| | | if (filter.getResourceId() != null) { |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("resource_id").is(filter.getResourceId()))); |
| | | } |
| | | if (filter.getCategoryName() != null) { |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("free_type").contains(filter.getCategoryName()))); |
| | | if (filter.getResourceIds() != null && filter.getResourceIds().size() > 0) { |
| | | Criteria criteria = null; |
| | | for (Integer resourceId : filter.getResourceIds()) { |
| | | if (criteria == null) |
| | | criteria = Criteria.where("resource_id").is(resourceId); |
| | | else |
| | | criteria = criteria.or("resource_id").is(resourceId); |
| | | } |
| | | query.addFilterQuery(new SimpleFilterQuery(criteria)); |
| | | } |
| | | |
| | | if (filter.getArea() != null) { |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("area").contains(filter.getArea()))); |
| | | if (filter.getCategoryName() != null) { |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("category_names").contains(filter.getCategoryName()))); |
| | | } |
| | | |
| | | //区域 |
| | | if (filter.getAreas() != null && filter.getAreas().size() > 0) { |
| | | Criteria criteria = null; |
| | | for (String area : filter.getAreas()) { |
| | | if (criteria == null) |
| | | criteria = Criteria.where("area").is(area); |
| | | else |
| | | criteria = criteria.or("area").is(area); |
| | | } |
| | | query.addFilterQuery(new SimpleFilterQuery(criteria)); |
| | | } |
| | | |
| | | if (filter.getTag() != null) { |
| | | query.addFilterQuery(new SimpleFilterQuery(Criteria.where("tag").is(filter.getTag()))); |
| | | } |
| | | |
| | | |
| | |
| | | return new SolrResultDTO(list, (int) result.getTotalElements()); |
| | | } |
| | | |
| | | public PlayUrl getPlayUrl(String id, VideoResource videoResource) { |
| | | //短视频 |
| | | if (VideoUtil.getVideoFromType(id) == HomeVideo.FROM_TYPE_SHORT) { |
| | | SolrShortVideo solrShortVideo = findOne(id); |
| | | if (solrShortVideo == null) |
| | | return null; |
| | | PlayUrl pu = new PlayUrl(); |
| | | pu.setParams(""); |
| | | pu.setPlayType(IqiyiUtil2.PLAY_HTML); |
| | | pu.setResource(videoResource); |
| | | pu.setUrl(solrShortVideo.getPlayUrl()); |
| | | return pu; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |