You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ninad Raut <hb...@gmail.com> on 2009/08/10 14:25:12 UTC

Pojo not getting added to Solr Index

I am not getting any excpetion, but the document is not getting added to
Solr.
Here is the code:
public class ClientSearch {

 public SolrServer getSolrServer() throws MalformedURLException{
  //the instance can be reused
  return new CommonsHttpSolrServer("http://germinait22:8983/solr/core0/");
 }

 void store() throws IOException, SolrServerException {
  IthursDocument ithursDocument = new IthursDocument();
  System.out.println("Created IthursDocument..");
  ithursDocument.setId("testID_2");
  ithursDocument.setMedia("BLOG");
  ithursDocument.setContent("Khatoo is a good Gal");
  Date date = new Date("23/08/2009");
  ithursDocument.setPubDate(date);
  Map<String,String> namedEntity = new HashMap<String,String>();
  namedEntity.put("Germinait", "0.7");
  ithursDocument.setNe(namedEntity);
  ithursDocument.setSentiment(0.1f);
  SolrServer server = getSolrServer();
  server.addBean(ithursDocument);
 }

 void query() throws MalformedURLException, SolrServerException {
  SolrServer server = getSolrServer();
  SolrQuery query = new SolrQuery();
  query.setQuery("id:testID");

  QueryResponse rsp = server.query(query);
  List<IthursDocument> list= rsp.getBeans(IthursDocument.class);
  System.out.println(list.size());

 }

 public static void main(String[] args) {
  ClientSearch clientSearch = new ClientSearch();
  try {
  clientSearch.store();
  clientSearch.query();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (SolrServerException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
 }
The logs show the following:
192.168.0.115 - - [10/08/2009:12:10:47 +0000] "POST
/solr/core0/update?wt=javabin&version=1 HTTP/1.1" 200 40
Where am I going wrong??

Re: Pojo not getting added to Solr Index

Posted by Ninad Raut <hb...@gmail.com>.
thanks Avlesh, u saved my day... !! yes I am not going to have a new
instance of server every time...  this is just a Proof of concept.

On Mon, Aug 10, 2009 at 6:06 PM, Avlesh Singh <av...@gmail.com> wrote:

> >
> > Where am I going wrong??
> >
> I think you forgot to "commit" after adding beans via the SolrServer.
>
> PS: I am damn sure that you don't intend to create a new instance of
> CommonsHttpSolrServer everytime.
>
> Cheers
> Avlesh
>
> On Mon, Aug 10, 2009 at 5:55 PM, Ninad Raut <hbase.user.ninad@gmail.com
> >wrote:
>
> > I am not getting any excpetion, but the document is not getting added to
> > Solr.
> > Here is the code:
> > public class ClientSearch {
> >
> >  public SolrServer getSolrServer() throws MalformedURLException{
> >  //the instance can be reused
> >  return new CommonsHttpSolrServer("http://germinait22:8983/solr/core0/
> ");
> >  }
> >
> >  void store() throws IOException, SolrServerException {
> >  IthursDocument ithursDocument = new IthursDocument();
> >  System.out.println("Created IthursDocument..");
> >  ithursDocument.setId("testID_2");
> >  ithursDocument.setMedia("BLOG");
> >  ithursDocument.setContent("Khatoo is a good Gal");
> >  Date date = new Date("23/08/2009");
> >  ithursDocument.setPubDate(date);
> >  Map<String,String> namedEntity = new HashMap<String,String>();
> >  namedEntity.put("Germinait", "0.7");
> >  ithursDocument.setNe(namedEntity);
> >  ithursDocument.setSentiment(0.1f);
> >  SolrServer server = getSolrServer();
> >  server.addBean(ithursDocument);
> >  }
> >
> >  void query() throws MalformedURLException, SolrServerException {
> >  SolrServer server = getSolrServer();
> >  SolrQuery query = new SolrQuery();
> >  query.setQuery("id:testID");
> >
> >  QueryResponse rsp = server.query(query);
> >  List<IthursDocument> list= rsp.getBeans(IthursDocument.class);
> >  System.out.println(list.size());
> >
> >  }
> >
> >  public static void main(String[] args) {
> >  ClientSearch clientSearch = new ClientSearch();
> >  try {
> >  clientSearch.store();
> >  clientSearch.query();
> >  } catch (IOException e) {
> >  // TODO Auto-generated catch block
> >  e.printStackTrace();
> >  } catch (SolrServerException e) {
> >  // TODO Auto-generated catch block
> >  e.printStackTrace();
> >  }
> >  }
> > The logs show the following:
> > 192.168.0.115 - - [10/08/2009:12:10:47 +0000] "POST
> > /solr/core0/update?wt=javabin&version=1 HTTP/1.1" 200 40
> > Where am I going wrong??
> >
>

Re: Pojo not getting added to Solr Index

Posted by Avlesh Singh <av...@gmail.com>.
>
> Where am I going wrong??
>
I think you forgot to "commit" after adding beans via the SolrServer.

PS: I am damn sure that you don't intend to create a new instance of
CommonsHttpSolrServer everytime.

Cheers
Avlesh

On Mon, Aug 10, 2009 at 5:55 PM, Ninad Raut <hb...@gmail.com>wrote:

> I am not getting any excpetion, but the document is not getting added to
> Solr.
> Here is the code:
> public class ClientSearch {
>
>  public SolrServer getSolrServer() throws MalformedURLException{
>  //the instance can be reused
>  return new CommonsHttpSolrServer("http://germinait22:8983/solr/core0/");
>  }
>
>  void store() throws IOException, SolrServerException {
>  IthursDocument ithursDocument = new IthursDocument();
>  System.out.println("Created IthursDocument..");
>  ithursDocument.setId("testID_2");
>  ithursDocument.setMedia("BLOG");
>  ithursDocument.setContent("Khatoo is a good Gal");
>  Date date = new Date("23/08/2009");
>  ithursDocument.setPubDate(date);
>  Map<String,String> namedEntity = new HashMap<String,String>();
>  namedEntity.put("Germinait", "0.7");
>  ithursDocument.setNe(namedEntity);
>  ithursDocument.setSentiment(0.1f);
>  SolrServer server = getSolrServer();
>  server.addBean(ithursDocument);
>  }
>
>  void query() throws MalformedURLException, SolrServerException {
>  SolrServer server = getSolrServer();
>  SolrQuery query = new SolrQuery();
>  query.setQuery("id:testID");
>
>  QueryResponse rsp = server.query(query);
>  List<IthursDocument> list= rsp.getBeans(IthursDocument.class);
>  System.out.println(list.size());
>
>  }
>
>  public static void main(String[] args) {
>  ClientSearch clientSearch = new ClientSearch();
>  try {
>  clientSearch.store();
>  clientSearch.query();
>  } catch (IOException e) {
>  // TODO Auto-generated catch block
>  e.printStackTrace();
>  } catch (SolrServerException e) {
>  // TODO Auto-generated catch block
>  e.printStackTrace();
>  }
>  }
> The logs show the following:
> 192.168.0.115 - - [10/08/2009:12:10:47 +0000] "POST
> /solr/core0/update?wt=javabin&version=1 HTTP/1.1" 200 40
> Where am I going wrong??
>