Solrj

solr 的java客户端可比python复杂一些,贴点代码:

	public static void main(String[] args) throws MalformedURLException, SolrServerException {
		CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://192.168.1.100:7100/solr/feed");
		server.setSoTimeout(1000);
		server.setConnectionTimeout(100);
		server.setDefaultMaxConnectionsPerHost(100);
		server.setMaxTotalConnections(100);
		server.setAllowCompression(true);
		server.setParser(new XMLResponseParser());

		SolrQuery query = new SolrQuery();
		query.setQuery("*:*");
		query.setStart(24);
		query.setRows(48);
		// query.addSortField("price", SolrQuery.ORDER.asc);
		QueryResponse rsp = server.query(query);
		SolrDocumentList docs = rsp.getResults();
		for (SolrDocument doc : docs) {
			System.out.println(doc.get("id"));
		}
		System.out.println("---------------------");
		System.out.println(docs.size());
		System.out.println(docs.getNumFound());

	}

 

文档直接参考官方好了:http://wiki.apache.org/solr/Solrj

你可能感兴趣的:(solrj)