lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ankita shinde <ankitashinde...@gmail.com>
Subject solrj
Date Sat, 02 Oct 2010 18:30:24 GMT
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?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message