I asked the exact question the day before. If you or anyone else has pointer to the solution, please share on the mail list. For now, I am using Perl script instead to query Solr server.
Thanks, Xin -----Original Message----- From: ankita shinde [mailto:ankitashinde...@gmail.com] Sent: Saturday, October 02, 2010 2:30 PM To: solr-user@lucene.apache.org Subject: solrj hello, I am trying to use solrj for interfacing with solr. I am trying to run the SolrjTest example. I have included all the following jar files- - commons-codec-1.3.jar - commons-fileupload-1.2.1.jar - commons-httpclient-3.1.jar - commons-io-1.4.jar - geronimo-stax-api_1.0_spec-1.0.1.jar - apache-solr-solrj-*.jar - wstx-asl-3.2.7.jar - slf4j-api-1.5.5.jar - slf4j-simple-1.5.5.jar *My SolrjTest file is as follows:* import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrDocument; import java.util.Map; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrDocument; import java.util.Map; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.HashMap; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.FacetField; class SolrjTest { public void query(String q) { CommonsHttpSolrServer server = null; try { server = new CommonsHttpSolrServer("http://localhost:8983/solr/ "); } catch(Exception e) { e.printStackTrace(); } SolrQuery query = new SolrQuery(); query.setQuery(q); query.setQueryType("dismax"); query.setFacet(true); query.addFacetField("lastname"); query.addFacetField("locality4"); query.setFacetMinCount(2); query.setIncludeScore(true); try { QueryResponse qr = server.query(query); SolrDocumentList sdl = qr.getResults(); System.out.println("Found: " + sdl.getNumFound()); System.out.println("Start: " + sdl.getStart()); System.out.println("Max Score: " + sdl.getMaxScore()); System.out.println("--------------------------------"); ArrayList<HashMap<String, Object>> hitsOnPage = new ArrayList<HashMap<String, Object>>(); for(SolrDocument d : sdl) { HashMap<String, Object> values = new HashMap<String, Object>(); for(Iterator<Map.Entry<String, Object>> i = d.iterator(); i.hasNext(); ) { Map.Entry<String, Object> e2 = i.next(); values.put(e2.getKey(), e2.getValue()); } hitsOnPage.add(values); System.out.println(values.get("displayname") + " (" + values.get("displayphone") + ")"); } List<FacetField> facets = qr.getFacetFields(); for(FacetField facet : facets) { List<FacetField.Count> facetEntries = facet.getValues(); for(FacetField.Count fcount : facetEntries) { System.out.println(fcount.getName() + ": " + fcount.getCount()); } } } catch (SolrServerException e) { e.printStackTrace(); } } public static void main(String[] args) { SolrjTest solrj = new SolrjTest(); solrj.query(args[0]); } } But its giving me error as 'NoClassDefFoundError: org/apache/solr/client/solrj/SolrServerException'. Can anyone tell me where did i go wrong? This electronic mail message contains information that (a) is or may be CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the addressee(s) named herein. If you are not an intended recipient, please contact the sender immediately and take the steps necessary to delete the message completely from your computer system. Not Intended as a Substitute for a Writing: Notwithstanding the Uniform Electronic Transaction Act or any other law of similar effect, absent an express statement to the contrary, this e-mail message, its contents, and any attachments hereto are not intended to represent an offer or acceptance to enter into a contract and are not otherwise intended to bind this sender, barnesandnoble.com llc, barnesandnoble.com inc. or any other person or entity.