安装路径:
apache-tomcat-6.0.41\bin\solr\collection1\conf
重点配置文件:
data-config.xml
url="jdbc:mysql://192.168.3.12/jqtest"
user="root"
password="123456"/>
schema.xml
solrconfig.xml
启动tomcat, 进入http://localhost:8080/solr
点击DataImport, 然后Qurey. 查询条件q: "*:*" 有结果显示. Solr安装配置成功.
项目中导入如下包:
apache-solr-solrj-4.0.0.jar
httpclient-4.1.3.jar
httpcore-4.1.4.jar
httpmime-4.1.3.jar
测试代码:
public class SolrMain {
/**
* @param args
* @throws SolrServerException
*/
public static void main(String[] args) throws SolrServerException {
String url = "http://localhost:8080/solr";
SolrServer server = new HttpSolrServer(url);
SolrQuery query = new SolrQuery("*方案*");
QueryResponse response = server.query(query);
SolrDocumentList docs = response.getResults();
System.out.println("文档个数:" + docs.getNumFound());
System.out.println("查询时间:" + response.getQTime());
for (SolrDocument doc : docs) {
System.out.println("id: " + doc.getFieldValue("newsId"));
System.out.println("title: " + doc.getFieldValue("title"));
System.out.println();
}
}
}
运行结果:
文档个数:9
查询时间:6
id: 2
title: 关于进取
id: 11
title: 销售
id: 17
title: test-消息test
id: 18
title: test-消息01
id: 28
title: test-解决方案-政府行业
id: 29
title: test-解决方案-金融行业
id: 30
title: 市民卡解决方案
id: 31
title: 决策支持解决方案
id: 32
title: 银行卡运营外包解决方案