2017-05-04 3 views
0

solr에 요청하는 각 요청에 대해 먼저 호출되는 (사용자 정의 http 필터가 org.apache.solr.servlet.SolrDispatchFilter 이전에 실행 됨) 구성되었습니다. 커스텀 필터는 들어오는 모든 solr 요청에서 특정 요청 헤더를 찾는다. solr에 의해 추가 처리를 위해 그것을 보낸다.SolrJ를 사용하여 사용자 정의 요청 헤더 설정하기

특정 쿼리에는 SolrJ가 사용됩니다. Solr을 통해 Solr을 쿼리 할 때 HTTP 요청 헤더를 설정할 수있는 방법이 있습니까?

내 SOLR 및 SorlJ 버전은 당신이 당신의 자신의 클래스 MyHttpSolrClient를 만드는 HttpSolrClient을 확장하고 사용자 요청 헤더를 추가 executeMethod의 동작을 사용자 정의 할 수 있습니다 5.4.0

답변

0

입니다.

public class MyHttpSolrClient extends HttpSolrClient { 

    public MyHttpSolrClient(String baseURL) { 
    super(baseURL); 
    } 

    public MyHttpSolrClient(String baseURL, HttpClient client) { 
    super(baseURL, client); 
    } 

    public MyHttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) { 
    super(baseURL, client, parser); 
    } 

    protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException { 

    // **Here you add your custom header** 
    method.addHeader("Name", "Value"); 

    return super.executeMethod(method, processor); 
    } 
} 
관련 문제