admin
2021-03-03 b25591e02ffa14f03d4dd903cfcabdb8678cc0c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
    }
 
 
}