solr 4.0 설치 및 사용
1. apache - solr - 4.0.0. zip 가방 에 있 는 solr. war 프로젝트 copy 에서 $TOMCATHOME / webapps 디 렉 터 리 아래
2.$TOMCAT_HOME / conf / Catalina / localhost 에 새로 만 든 solr. xml 파일
xml:
<Context docBase="E:/temp/tomcat/webapps/solr" debug="0" crossContext="true" >
<Environment name="solr/home" type="java.lang.String" value="E:/temp/tomcat/work/Catalina/localhost/solr" override="true" />
</Context>
3. 중국어 분사 기 도입: IKAnalyzer2012 FFu1. jar, IKAnalyzer. cfg. xml, stopword. dic 3 개의 파일 을 solr 프로젝트 의 lib 디 렉 터 리 에 복사 하여 $TOMCATHOME \ \ work \ Catalina \ localhost \ solr \ collection 2 \ \ conf \ schema. xml 의 < type > < / type > 중간 추가:
<!--ik_anlyzer-->
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
<analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
4. 배치 완료, 호출 (원 격 http 프로 토 콜 전송 파일 가능)
private static final String url = "http://127.0.0.1:8888/solr/";
public static HttpSolrServer getSolrServer() {
HttpSolrServer server = new HttpSolrServer(url);
server.setMaxRetries(1);
server.setConnectionTimeout(5000);
server.setParser(new XMLResponseParser());
server.setSoTimeout(1000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false);
server.setAllowCompression(true);
return server;
}
public static void create() throws SolrServerException, IOException{
HttpSolrServer server = getSolrServer();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", System.currentTimeMillis());
doc.addField("title", "60 ");
server.add(doc);
server.commit();
}
public static void search() throws SolrServerException{
SolrServer server = getSolrServer();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
QueryResponse rsp = server.query(query);
SolrDocumentList docs = rsp.getResults();
for (SolrDocument sd : docs) {
System.out.println(sd.toString());
}
}