solrJ查询使用方法
程序员文章站
2024-02-22 12:03:10
...
public class SolrJSearch {
private static final String SOLR_URL =
//"http://10.0.8.10:8081/solr/spacearticle/";
"http://localhost:8080/solr/";
private CommonsHttpSolrServer solrServer = null;
public SolrJSearch(){
try {
solrServer = new CommonsHttpSolrServer(SOLR_URL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public void search(){
SolrQuery query = new SolrQuery();
query.setQuery("A_Title:新浪科技");
//排序用的
//query.addSortField( "price", SolrQuery.ORDER.asc );
try {
QueryResponse rsp = solrServer.query( query );
SolrDocumentList docs = rsp.getResults();
System.out.println("文档个数:" + docs.getNumFound());
System.out.println("查询时间:" + rsp.getQTime());
for (SolrDocument doc : docs) {
String title = (String) doc.getFieldValue("A_Title");
Integer id = (Integer) doc.getFieldValue("A_ID");
System.out.println(id);
System.out.println(title);
}
} catch (SolrServerException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SolrJSearch sj = new SolrJSearch();
sj.search();
}
}
上一篇: memset初始化为特定的值遇到的坑
下一篇: centos 7.x 部署nginx环境