package com.hxh.spring.test;
|
|
import com.yeshi.buwan.dao.HomeNoticeDao;
|
import com.yeshi.buwan.domain.SolrVideo;
|
import com.yeshi.buwan.dto.search.SolrResultDTO;
|
import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.manager.SolrAlbumDataManager;
|
import org.apache.http.auth.Credentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.junit.Test;
|
import org.junit.runner.RunWith;
|
import org.springframework.data.solr.core.SolrTemplate;
|
import org.springframework.data.solr.server.support.HttpSolrClientFactory;
|
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
import javax.annotation.Resource;
|
import java.security.Principal;
|
import java.util.Optional;
|
|
|
//Optional@RunWith(SpringJUnit4ClassRunner.class)
|
//@ContextConfiguration(locations = {"classpath:spring.xml"})
|
//@WebAppConfiguration
|
public class SolrTest {
|
|
@Resource
|
private SolrAlbumDataManager solrDataManager;
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@Resource
|
private HomeNoticeDao homeNoticeDao;
|
|
@Test
|
public void test1() {
|
SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
|
filter.setKey("");
|
filter.setVideoType(null);
|
filter.setContentType(1);
|
// filter.setResourceIds(new String[]{"24"});
|
|
SolrResultDTO dto = solrDataManager.find(filter, 1, 10);
|
System.out.println(dto);
|
}
|
|
@Test
|
public void addSolrAlbum() {
|
// solrDataManager.syncAlbum("8224447");
|
SolrClient solrClient = new HttpSolrClient.Builder("http://203.195.196.115:8983/solr").build();
|
Credentials credentials = new UsernamePasswordCredentials("solr", "IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c=");
|
HttpSolrClientFactory factory = new HttpSolrClientFactory(solrClient, null, null);
|
SolrTemplate solrTemplate = new SolrTemplate(factory);
|
solrTemplate.afterPropertiesSet();
|
Optional<SolrVideo> solrVideoOptional = solrTemplate.getById("buwan_album", "8077525", SolrVideo.class);
|
System.out.println(solrVideoOptional);
|
}
|
|
|
}
|