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 Nikhil Chhaochharia <ni...@yahoo.com> on 2008/08/28 11:16:52 UTC

CoreDescriptor explanation and possible bug

Hi,

I have been using nightly builds of Solr 1.3 with SolrJ for some time now.  I upgraded the Solr jars from the 14-Aug nightly and my program would not compile.  I found that SolrCore constructor needed a new parameter CoreDescriptor.  I passed null and it worked fine.

I then upgraded to the Solr jars from the 20th-Aug nightly and it started throwing NullPointerExceptions.  My guess is that the addition of the method SolrCore.getStatistics() which has the line "lst.add("aliases", getCoreDescriptor().getCoreContainer().getCoreNames(this));" throws the NPE.

I searched the wiki and there is no mention of CoreDescriptor there.  Could somebody please explain what CoreDescriptor is all about and how it is supposed to be used?

Thanks,
Nikhil


Re: CoreDescriptor explanation and possible bug

Posted by Henrib <hb...@gmail.com>.
Hi,
It is likely to be related to how you initialize Solr & create your
SolrCore; there has been a few changes to ensure there is always a
CoreContainer created which (as its name stands), holds a reference to all
created SolrCore.
There is a CoreContainer.Initializer class that allows to easily create that
CoreContainer (even if you don't have a solr.xml).
Hope this helps,
Henri



Nikhil Chhaochharia wrote:
> 
> Hi,
> 
> I have been using nightly builds of Solr 1.3 with SolrJ for some time now. 
> I upgraded the Solr jars from the 14-Aug nightly and my program would not
> compile.  I found that SolrCore constructor needed a new parameter
> CoreDescriptor.  I passed null and it worked fine.
> 
> I then upgraded to the Solr jars from the 20th-Aug nightly and it started
> throwing NullPointerExceptions.  My guess is that the addition of the
> method SolrCore.getStatistics() which has the line "lst.add("aliases",
> getCoreDescriptor().getCoreContainer().getCoreNames(this));" throws the
> NPE.
> 
> I searched the wiki and there is no mention of CoreDescriptor there. 
> Could somebody please explain what CoreDescriptor is all about and how it
> is supposed to be used?
> 
> Thanks,
> Nikhil
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/CoreDescriptor-explanation-and-possible-bug-tp19197004p19198965.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: CoreDescriptor explanation and possible bug

Posted by Henrib <hb...@gmail.com>.
Seems you want something like:

  public SolrCore nikhilInit(final IndexSchema indexSchema) {
    final String solrConfigFilename = "solrconfig.xml"; // or else
    CoreContainer.Initializer init = new CoreContainer.Initializer() {
      @Override
      public CoreContainer initialize() {
      CoreContainer container = new CoreContainer(new
SolrResourceLoader(SolrResourceLoader.locateInstanceDir()));
        SolrConfig solrConfig = solrConfigFilename == null ? new
SolrConfig() : new SolrConfig(solrConfigFilename);
        CoreDescriptor dcore = new CoreDescriptor("",
solrConfig.getResourceLoader().getInstanceDir());
        //dcore.setCoreContainer(container);
        dcore.setConfigName(solrConfig.getResourceName());
        dcore.setSchemaName(indexSchema.getResourceName());
        SolrCore core = new SolrCore( "", null, cfg, indexSchema, dcore);
        container.register("", core, false);
        return container;
    }
    };
    return init.initialize().getCore("");
  }


-- 
View this message in context: http://www.nabble.com/CoreDescriptor-explanation-and-possible-bug-tp19197004p19200585.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: CoreDescriptor explanation and possible bug

Posted by Henrib <hb...@gmail.com>.

Nikhil Chhaochharia wrote:
> 
> 
> I am assuming that these are part of some patch which will get applied
> before 1.3 releases, is that correct ?
> 
> Nikhil
> 
> 

Yes, this is part of a patch and no, they most likely will not make it in
1.3.
However, I guess the following will bring you even closer:


  public SolrCore nikhilInit(final IndexSchema indexSchema) {
    final String solrConfigFilename = "solrconfig.xml"; // or else
    CoreContainer.Initializer init = new CoreContainer.Initializer() {
      @Override
      public CoreContainer initialize() {
      CoreContainer container = new CoreContainer(new
SolrResourceLoader(SolrResourceLoader.locateInstanceDir()));
        SolrConfig solrConfig = solrConfigFilename == null ? new
SolrConfig() : new SolrConfig(solrConfigFilename);
        CoreDescriptor dcore = new CoreDescriptor(container, "",
solrConfig.getResourceLoader().getInstanceDir());
        dcore.setConfigName(solrConfig.getResourceName());
        dcore.setSchemaName(indexSchema.getResourceName());
        SolrCore core = new SolrCore( "", null, solrConfig, indexSchema,
dcore);
        container.register("", core, false);
        return container;
    }
    };
    return init.initialize().getCore("");
  }



-- 
View this message in context: http://www.nabble.com/CoreDescriptor-explanation-and-possible-bug-tp19197004p19201459.html
Sent from the Solr - User mailing list archive at Nabble.com.