On May 10, 2006, at 3:01 PM, Yonik Seeley wrote:

On 5/10/06, Erik Hatcher <[EMAIL PROTECTED]> wrote:
I've started down this route, but I'm not sure how to initialize my
cache the first time.

I need access to the IndexReader to build the cache, and at this
point I don't need any incremental cache updates - if a new
IndexSearcher is swapped in, I want to rebuild the cache.

Should I combine a custom SolrCache with a newSearcher listener to
have it generated right away?   I put in a dummy cache and
regenerator, but only see the cache .init() method being called, not
the warm() method (on application server startup).  How can I
bootstrap it such that my cache gets built on app. startup?

If your cache is populated as the result of any request to your
plugin, simply send a request via a firstSearcher hook.  If it's not
populated for any request, then send a special request that your
plugin would recognize as a "populate cache" request.

Sorry I'm being dense today, though I really do appreciate the incredibly fast response time you and Hoss have on this. My cache is not available in newSearcher() at startup time:

public class CacheFacetsListener implements SolrEventListener {
  public void init(NamedList namedList) {
  }

  public void postCommit() {
    throw new UnsupportedOperationException();
  }

public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
    try {
      SolrCache cache = newSearcher.getCache("facet_cache");
      if (cache == null) {
        System.out.println("!!!!! cache is null");
      }
      cache.warm(newSearcher, null);
    } catch (IOException e) {
      log.severe(e.getMessage());
    }
  }
}

I'm getting the "cache is null" message. Though the cache is created and init()'d as I see it's diagnostic output in Jetty's console before the NPE:

public class FacetCache implements SolrCache {
private Map facetCache; // key is field, and key to inner map is value
  private State state;

  private void loadFacets(IndexReader reader) throws IOException {
System.out.println("Loading facets for " + reader.numDocs() + " documents ...");

    // ....

    System.out.println("Done loading facets.");
  }


public Object init(Map args, Object persistence, CacheRegenerator regenerator) {
    state=State.CREATED;
    System.out.println("<<<<< FacetCache.init >>>>>");
    return persistence;
  }

  // ......

}

And from solrconfig.xml:

    <cache name="facet_cache"
      class="org.nines.FacetCache"
    />

The console has this output:

May 10, 2006 3:44:26 PM org.apache.solr.search.SolrIndexSearcher <init>
INFO: Opening [EMAIL PROTECTED] main
<<<<< FacetCache.init >>>>>
May 10, 2006 3:44:26 PM org.apache.solr.core.SolrCore registerSearcher
INFO: Registered new searcher [EMAIL PROTECTED] main
!!!!! cache is null
May 10, 2006 3:44:26 PM org.apache.solr.core.SolrException log
SEVERE: java.lang.NullPointerException
at org.nines.CacheFacetsListener.newSearcher (CacheFacetsListener.java:24)
        at org.apache.solr.core.SolrCore$2.call(SolrCore.java:427)


I'm probably making this more difficult than it needs to be, but today I'm slow :) What am I doing wrong?

Thanks,
        Erik

Reply via email to