Fixing NPE in VClassGroupCache at startup with empty Solr NIHVIVO-3460

This commit is contained in:
briancaruso 2011-12-08 21:50:05 +00:00
parent 0cf492d729
commit cf31ff4548
2 changed files with 38 additions and 7 deletions

View file

@ -340,6 +340,7 @@ public class VClassGroupCache implements IndexingEventListener {
if( group == null ) return;
String groupUri = group.getURI();
String facetOnField = VitroSearchTermNames.RDFTYPE;
SolrQuery query = new SolrQuery( ).
setRows(0).
@ -347,7 +348,7 @@ public class VClassGroupCache implements IndexingEventListener {
setQuery(VitroSearchTermNames.CLASSGROUP_URI + ":" + groupUri ).
//facet on type to get counts for classes in classgroup
setFacet(true).
addFacetField( VitroSearchTermNames.RDFTYPE ).
addFacetField( facetOnField ).
setFacetMinCount(0);
log.debug("query: " + query);
@ -358,12 +359,22 @@ public class VClassGroupCache implements IndexingEventListener {
log.debug("Number of individuals found " + individualCount);
group.setIndividualCount((int) individualCount);
//get counts for classes
FacetField ff = rsp.getFacetField( VitroSearchTermNames.RDFTYPE );
List<Count> counts = ff.getValues();
for( Count ct: counts){
String classUri = ct.getName();
long individualsInClass = ct.getCount();
setClassCount( group, classUri, individualsInClass);
FacetField ff = rsp.getFacetField( facetOnField );
if( ff != null ){
List<Count> counts = ff.getValues();
if( counts != null ){
for( Count ct: counts){
if( ct != null ){
String classUri = ct.getName();
long individualsInClass = ct.getCount();
setClassCount( group, classUri, individualsInClass);
}
}
}else{
log.debug("no Counts found for FacetField " + facetOnField);
}
}else{
log.debug("no FaccetField found for " + facetOnField);
}
}

View file

@ -0,0 +1,20 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.indexing;
/**
* Classes that implement this interface can get informed of
* events that happen to the IndexBuilder.
*/
public interface IndexingEventListener {
public enum EventTypes {
START_UPDATE,
FINISHED_UPDATE,
START_FULL_REBUILD,
FINISH_FULL_REBUILD,
SHUTDOWN
}
public void notifyOfIndexingEvent(EventTypes ie);
}