2017-04-13 4 views
-1
내가 자바 라이브러리에있는 jar 파일을 추가하고, SOLR에 연결을 시도해야

코드는 다음과 같습니다 :solrJ 오류가 HttpSolrServer 및 SolrServer

import java.net.MalformedURLException; 
import org.apache.solr.client.solrj.SolrServer; 
import org.apache.solr.client.solrj.SolrServerException; 
import org.apache.solr.client.solrj.impl.HttpSolrServer; 
import org.apache.solr.client.solrj.response.QueryResponse; 
import org.apache.solr.common.params.ModifiableSolrParams; 

public class SolrQuery { 
    public static void main(String[] args) throws MalformedURLException, SolrServerException { 
    SolrServer server = new HttpSolrServer("http://localhost:8080/solr"); 
     ModifiableSolrParams params = new ModifiableSolrParams(); 
     params.set("q", "1"); 

      QueryResponse response = server.query(params); 

      System.out.println("response = " + response); 

    } 
} 

하지만 난 프로그램을 실행하려고 할 때, 난 오류 :

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    SolrServer cannot be resolved to a type 
    HttpSolrServer cannot be resolved to a type 
    The type org.apache.solr.common.params.SolrParams cannot be resolved. It is indirectly referenced from required .class files 

어떻게 해결할 수 있습니까?

+0

컬렉션 이름에 url 또는 컬렉션 이름을 추가하십시오. – vinod

+0

@vinod 나는 solr에서 새롭다, 더 특정 일 수 있는가? –

+0

답을 확인하십시오. – vinod

답변

0

서버 URL에서 문서를 색인 생성 한 컬렉션/코어 이름을 추가하십시오.

SolrServer server = new HttpSolrServer ("http://localhost:8080/solr/collection");

예제 자바 코드 참조 용.

* solr에 색인 된 모든 문서를 제공합니다. 검색하려는 키워드 문자열에 *을 변경하십시오.

import org.apache.solr.client.solrj.SolrQuery; 
import org.apache.solr.client.solrj.SolrServerException; 
import org.apache.solr.client.solrj.impl.HttpSolrServer; 
import org.apache.solr.client.solrj.response.QueryResponse; 
import org.apache.solr.common.SolrDocumentList; 

public class SearchSolr { 

    public static void main(String[] args) throws SolrServerException { 
     HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr/collection1"); 
     SolrQuery query = new SolrQuery(); 
     query.setQuery("*"); 
     QueryResponse response = solr.query(query); 
     SolrDocumentList results = response.getResults(); 
     for (int i = 0; i < results.size(); ++i) { 
      System.out.println(results.get(i)); 
     } 
    } 
} 
+0

sry, 그냥 코드를 시도하고 같은 오류가 발생했습니다 : 스레드 "main "상위를 : 해결되지 않은 컴파일 문제 : \t 생성자 HttpSolrServer (문자열) 정의되지 \t 방법의 setQuery (문자열) 방법 쿼리 (SolrQuery가) 유형에 대한 정의되지 않은 유형의 SolrQuery \t에 대한 정의되지 HttpSolrServer \t 유형 java.util.Map $ Entry을 (를) 확인할 수 없습니다. 필수 .class 파일에서 간접적으로 참조됩니다. –

+0

solrJ jar 파일을 추가 했습니까? – vinod

+0

다음은 가져온 파일입니다. commons-io-2.5, httpclient-4.4.1, httpcore-4.4.1, httpmime-4.4.1, jcl-over-slf4j-1.7.7, noggit-0.6 , slf4j-api-1.7.7, stax2-api-3.1.4, woodstox-core-asl-4.4.1 , 사육자 -3.4.6, solr-solrj-6.5. 0 –