diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java index 6dc2a7d8d..455d6bffa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java @@ -30,6 +30,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; import edu.cornell.mannlib.vitro.webapp.search.beans.FileBasedProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; @@ -116,7 +117,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ server.setMaxTotalConnections(100); server.setMaxRetries(1); - context.setAttribute(SOLR_SERVER, server); + context.setAttribute(SOLR_SERVER, server); /* set up the individual to solr doc translation */ OntModel jenaOntModel = ModelContext.getJenaOntModel(context); @@ -127,34 +128,23 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ * objects. This allows other ContextListeners to add to * the basic set of DocumentModifiers. */ @SuppressWarnings("unchecked") - List modifiers = - (List)context.getAttribute("DocumentModifiers"); - if( modifiers == null ) - modifiers = new ArrayList(); - - modifiers.add( new NameFields( RDFServiceUtils.getRDFServiceFactory(context))); - modifiers.add( new NameBoost( 1.2f )); - modifiers.add( new ThumbnailImageURL(jenaOntModel)); + List modifiersFromContext = + (List)context.getAttribute("DocumentModifiers"); /* try to get context attribute SearchIndexExcludes * and use that as the start of the list of exclude * objects. This allows other ContextListeners to add to * the basic set of SearchIndexExcludes . */ @SuppressWarnings("unchecked") - List excludes = - (List)context.getAttribute("SearchIndexExcludes"); - if( excludes == null ) - excludes = new ArrayList(); - - excludes.add(new ExcludeBasedOnNamespace( INDIVIDUAL_NS_EXCLUDES )); - excludes.add(new ExcludeBasedOnTypeNamespace( TYPE_NS_EXCLUDES ) ); - excludes.add(new ExcludeBasedOnType( OWL_TYPES_EXCLUDES) ); - excludes.add(new ExcludeNonFlagVitro() ); - excludes.add( new SyncingExcludeBasedOnType( displayModel ) ); - - IndividualToSolrDocument indToSolrDoc = - new IndividualToSolrDocument(excludes, modifiers); + List searchIndexExcludesFromContext = + (List)context.getAttribute("SearchIndexExcludes"); + IndividualToSolrDocument indToSolrDoc = + setupTransltion(jenaOntModel, displayModel, + RDFServiceUtils.getRDFServiceFactory(context), + modifiersFromContext, + searchIndexExcludesFromContext); + /* setup solr indexer */ SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc); @@ -213,4 +203,44 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ return (SolrServer) ctx.getAttribute(SOLR_SERVER); } + + public static IndividualToSolrDocument setupTransltion( + OntModel jenaOntModel, + Model displayModel, + RDFServiceFactory rdfServiceFactory, + List modifiersFromContext, + List searchIndexExcludesFromContext + ) { + + /* try to get context attribute DocumentModifiers + * and use that as the start of the list of DocumentModifier + * objects. This allows other ContextListeners to add to + * the basic set of DocumentModifiers. */ + List modifiers = new ArrayList(); + if( modifiersFromContext != null ){ + modifiers.addAll( modifiersFromContext); + } + + modifiers.add( new NameFields( rdfServiceFactory )); + modifiers.add( new NameBoost( 1.2f )); + modifiers.add( new ThumbnailImageURL(jenaOntModel)); + + /* try to get context attribute SearchIndexExcludes + * and use that as the start of the list of exclude + * objects. This allows other ContextListeners to add to + * the basic set of SearchIndexExcludes . */ + List excludes = + new ArrayList(); + if( searchIndexExcludesFromContext != null ){ + excludes.addAll(searchIndexExcludesFromContext); + } + + excludes.add(new ExcludeBasedOnNamespace( INDIVIDUAL_NS_EXCLUDES )); + excludes.add(new ExcludeBasedOnTypeNamespace( TYPE_NS_EXCLUDES ) ); + excludes.add(new ExcludeBasedOnType( OWL_TYPES_EXCLUDES) ); + excludes.add(new ExcludeNonFlagVitro() ); + excludes.add( new SyncingExcludeBasedOnType( displayModel ) ); + + return new IndividualToSolrDocument(excludes, modifiers); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java index 3fc9d32d6..a10f07e05 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java @@ -7,23 +7,18 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.SolrInputField; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolutionMap; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; -import com.hp.hpl.jena.shared.Lock; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class ThumbnailImageURL implements DocumentModifier { @@ -44,15 +39,15 @@ public class ThumbnailImageURL implements DocumentModifier { " ?a ?downloadLocation . } " ; //" ?b ?thumbnailLocationURL . } "; - private Model model; + private RDFServiceFactory rsf; private Log log = LogFactory.getLog(ThumbnailImageURL.class); static VitroSearchTermNames term = new VitroSearchTermNames(); String fieldForThumbnailURL = term.THUMBNAIL_URL; - public ThumbnailImageURL(Model model){ - this.model = model; + public ThumbnailImageURL( RDFServiceFactory rsf ){ + this.rsf = rsf; } @Override @@ -84,35 +79,28 @@ public class ThumbnailImageURL implements DocumentModifier { QuerySolutionMap initialBinding = new QuerySolutionMap(); Resource uriResource = ResourceFactory.createResource(individual.getURI()); initialBinding.add("uri", uriResource); - - Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ); - model.getLock().enterCriticalSection(Lock.READ); - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, model, initialBinding); - try{ - ResultSet results = qExec.execSelect(); - while(results.hasNext()){ - QuerySolution soln = results.nextSolution(); - Iterator iter = soln.varNames() ; - while( iter.hasNext()){ - String name = iter.next(); - RDFNode node = soln.get( name ); - if( node != null ){ - result.append("" + node.toString()); - }else{ - log.info(name + " is null"); - } - } - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - model.getLock().leaveCriticalSection(); - } - + + RDFService rdf = rsf.getRDFService(); + try{ + ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, rdf); + while(results.hasNext()){ + QuerySolution soln = results.nextSolution(); + Iterator iter = soln.varNames() ; + while( iter.hasNext()){ + String name = iter.next(); + RDFNode node = soln.get( name ); + if( node != null ){ + result.append("" + node.toString()); + }else{ + log.info(name + " is null"); + } + } + } + }catch(Throwable t){ + log.error(t,t); + } finally{ + rdf.close(); + } return result.toString(); }