I got the solution. Attach one complete sample code I made as follows.

Thanks,
LB

package com.greatfree.Solr;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.client.solrj.beans.Field;

import java.net.MalformedURLException;

public class SolrJExample
{
        public static void main(String[] args) throws MalformedURLException,
SolrServerException
        {
                SolrServer solr = new CommonsHttpSolrServer("
http://192.168.210.195:8080/solr/CategorizedHub";);

                SolrQuery query = new SolrQuery();
                query.setQuery("*:*");
                QueryResponse rsp = solr.query(query);
                SolrDocumentList docs = rsp.getResults();
                System.out.println(docs.getNumFound());

                try
                {
                        SolrServer solrScore = new CommonsHttpSolrServer("
http://192.168.210.195:8080/solr/score";);
                        Score score = new Score();
                        score.id = "4";
                        score.type = "modern";
                        score.name = "iphone";
                        score.score = 97;
                        solrScore.addBean(score);
                        solrScore.commit();
                }
                catch (Exception e)
                {
                        System.out.println(e.toString());
                }

        }
}


On Sat, Jan 22, 2011 at 3:58 PM, Lance Norskog <goks...@gmail.com> wrote:

> The unit tests are simple and show the steps.
>
> Lance
>
> On Fri, Jan 21, 2011 at 10:41 PM, Bing Li <lbl...@gmail.com> wrote:
> > Hi, all,
> >
> > In the past, I always used SolrNet to interact with Solr. It works great.
> > Now, I need to use SolrJ. I think it should be easier to do that than
> > SolrNet since Solr and SolrJ should be homogeneous. But I cannot find a
> > tutorial that is easy to follow. No tutorials explain the SolrJ
> programming
> > step by step. No complete samples are found. Could anybody offer me some
> > online resources to learn SolrJ?
> >
> > I also noticed Solr Cell and SolrJ POJO. Do you have detailed resources
> to
> > them?
> >
> > Thanks so much!
> > LB
> >
>
>
>
> --
> Lance Norskog
> goks...@gmail.com
>

Reply via email to