From 04f9d9839919714075c66c702d1a2b3d6b278ef5 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 22 Nov 2013 13:46:32 -0500 Subject: [PATCH] VIVO-568 Exclude individuals whose most specific type is a Vitro term It looks like this was the intent of ExcludeNonFlagVitro, but it was getting the VClasses of the individual, which filtered out things like PropertyGroup, ClassGroup, etc. Changed it to test the most specific types instead, which seems to be right. --- .../documentBuilding/ExcludeNonFlagVitro.java | 71 +++++++++++-------- .../IndividualToSolrDocument.java | 3 + 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java index 3381423d0..fdd2df365 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java @@ -1,44 +1,57 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +import static edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument.DONT_EXCLUDE; + import java.util.List; -import org.apache.solr.common.SolrInputDocument; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; /** - * Exclude individuals with types from the Vitro namespace from the - * search index. (Other than old vitro Flag types). + * Exclude individuals with most specific types from the Vitro namespace from + * the search index. (Other than old vitro Flag types). */ public class ExcludeNonFlagVitro implements SearchIndexExcluder { + private static final Log log = LogFactory.getLog(ExcludeNonFlagVitro.class); - @Override - public String checkForExclusion(Individual ind) { - if( ind != null && ind.getVClasses() != null ) { - String excludeMsg = skipIfVitro(ind, ind.getVClasses() ); - if( excludeMsg != null) - return excludeMsg; - } - return null; - } + @Override + public String checkForExclusion(Individual ind) { + if (ind == null) { + return DONT_EXCLUDE; + } + + List mostSpecificTypeUris = ind.getMostSpecificTypeURIs(); + if (mostSpecificTypeUris == null) { + return DONT_EXCLUDE; + } + + String message = skipIfVitro(ind, mostSpecificTypeUris); + if (!StringUtils.equals(DONT_EXCLUDE, message)) { + log.debug("msg=" + message + ", individual=" + ind.getURI() + " (" + + ind.getLabel() + "), types=" + mostSpecificTypeUris); + } + return message; + } + + String skipIfVitro(Individual ind, List mostSpecificTypeUris) { + for (String typeUri : mostSpecificTypeUris) { + if (typeUri == null) { + continue; + } + if (typeUri.startsWith(VitroVocabulary.vitroURI + "Flag")) { + continue; + } + if (typeUri.startsWith(VitroVocabulary.vitroURI)) { + return "Skipped " + ind.getURI() + " because in " + + VitroVocabulary.vitroURI + " namespace"; + } + } + return DONT_EXCLUDE; + } - String skipIfVitro(Individual ind, List vclasses) { - for( VClass type: vclasses ){ - if( type != null && type.getURI() != null ){ - String typeURI = type.getURI(); - - if(typeURI.startsWith( VitroVocabulary.vitroURI ) - && ! typeURI.startsWith(VitroVocabulary.vitroURI + "Flag") ){ - - return "Skipped " + ind.getURI()+" because in " - + VitroVocabulary.vitroURI + " namespace"; - } - } - } - return null; - } - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java index c32bb2503..a2f62782c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java @@ -110,6 +110,9 @@ public class IndividualToSolrDocument { for( SearchIndexExcluder excluder : excludes){ try{ String msg = excluder.checkForExclusion(ind); + log.debug("individual=" + ind.getURI() + " (" + ind.getLabel() + + "), excluder=" + excluder + ", types=" + + ind.getMostSpecificTypeURIs() + ", msg=" + msg); if( msg != DONT_EXCLUDE) return msg; }catch (Exception e) {