Fixing bug with search exclusion

This commit is contained in:
briancaruso 2012-06-27 17:04:58 +00:00
parent a26e329ed6
commit f997b7073c
5 changed files with 127 additions and 13 deletions

View file

@ -17,6 +17,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
*/
public class ExcludeBasedOnType implements SearchIndexExcluder {
private static final String SKIP_MSG = "skipping due to type.";
/** The add, set and remove methods must keep this list sorted. */
List<String> typeURIs;
public ExcludeBasedOnType(String ... typeURIs) {
@ -25,22 +28,41 @@ public class ExcludeBasedOnType implements SearchIndexExcluder {
@Override
public String checkForExclusion(Individual ind) {
if( ind != null ) {
List<VClass> vclasses = ind.getVClasses();
if( vclasses != null && ! Collections.disjoint(vclasses, typeURIs) ){
return("skipping due to type.");
}
}
if( ind == null )
return null;
if( typeURIinExcludeList( ind.getVClass() ))
return SKIP_MSG;
List<VClass> vclasses = ind.getVClasses();
if( vclasses == null)
return null;
for( VClass vclz : vclasses){
if( typeURIinExcludeList( vclz ))
return SKIP_MSG;
}
return null;
}
protected boolean typeURIinExcludeList( VClass vclz){
if( vclz != null && vclz.getURI() != null && !vclz.isAnonymous() ){
int pos = Collections.binarySearch(typeURIs, vclz.getURI());
return pos >= 0;
}else{
return false;
}
}
public void setExcludedTypes(String ... typeURIs){
setExcludedTypes(Arrays.asList(typeURIs));
}
public void setExcludedTypes(List<String> typeURIs){
synchronized(this){
this.typeURIs = new ArrayList<String>(typeURIs);
this.typeURIs = new ArrayList<String>(typeURIs) ;
Collections.sort( this.typeURIs );
}
}
@ -48,13 +70,14 @@ public class ExcludeBasedOnType implements SearchIndexExcluder {
if( typeURI != null && !typeURI.isEmpty()){
synchronized(this){
typeURIs.add(typeURI);
Collections.sort( this.typeURIs );
}
}
}
protected void removeTypeToExclude(String typeURI){
synchronized(this){
typeURIs.remove(typeURI);
typeURIs.remove(typeURI);
}
}
}

View file

@ -49,7 +49,7 @@ public class IndividualToSolrDocument {
try{
String excludeMsg = checkExcludes( ind );
if( excludeMsg != DONT_EXCLUDE){
log.debug(excludeMsg);
log.debug(ind.getURI() + " " + excludeMsg);
return null;
}
@ -235,7 +235,7 @@ public class IndividualToSolrDocument {
List<VClass> vclasses = ind.getVClasses(false);
if( vclasses == null || vclasses.isEmpty() ){
throw new SkipIndividualException("Not indexing because individual has no super classes");
throw new SkipIndividualException("Not indexing because individual has no classes");
}
for(VClass clz : vclasses){

View file

@ -41,6 +41,7 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
public SyncingExcludeBasedOnType( Model model){
this.setExcludedTypes( buildProhibitedClassesList(searchIndexURI, model) );
log.info("types excluded from search: " + typeURIs);
}
private List<String> buildProhibitedClassesList( String URI, Model model){
@ -68,7 +69,7 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
}catch(Throwable t){
log.error(t,t);
}finally{ qExec.close(); }
}finally{ model.leaveCriticalSection(); }
}finally{ model.leaveCriticalSection(); }
return newProhibitedClasses;
}
@ -83,11 +84,13 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
if( s.getObject() != null && s.getObject().canAs(Resource.class)){
String classURI = ((Resource)s.getObject().as(Resource.class)).getURI();
this.addTypeToExclude(classURI);
log.debug("prohibited classes: " + this.typeURIs);
}
}
}catch(Exception ex){
log.error("could not add statement",ex);
}
}
@Override
@ -96,7 +99,8 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
if( isExcludeClassPredicate( s ) && isAboutSearchIndex(s)){
if( s.getObject() != null && s.getObject().canAs(Resource.class)){
String classURI = ((Resource)s.getObject().as(Resource.class)).getURI();
this.removeTypeToExclude(classURI);
this.removeTypeToExclude(classURI);
log.debug("prohibited classes: " + this.typeURIs);
}
}
}catch(Exception ex){