Changes to Solr indexing building.

Added method to SolrSetup to make IndividualToSolrDocument.
Changed ThumbnailImageURL to use RDFServiceFactory.
This commit is contained in:
Brian Caruso 2012-10-30 14:52:21 -04:00
parent ac85ebf8c8
commit 8f8e9762f8
2 changed files with 80 additions and 62 deletions

View file

@ -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.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; 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.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.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.search.beans.FileBasedProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.FileBasedProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
@ -127,33 +128,22 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
* objects. This allows other ContextListeners to add to * objects. This allows other ContextListeners to add to
* the basic set of DocumentModifiers. */ * the basic set of DocumentModifiers. */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<DocumentModifier> modifiers = List<DocumentModifier> modifiersFromContext =
(List<DocumentModifier>)context.getAttribute("DocumentModifiers"); (List<DocumentModifier>)context.getAttribute("DocumentModifiers");
if( modifiers == null )
modifiers = new ArrayList<DocumentModifier>();
modifiers.add( new NameFields( RDFServiceUtils.getRDFServiceFactory(context)));
modifiers.add( new NameBoost( 1.2f ));
modifiers.add( new ThumbnailImageURL(jenaOntModel));
/* try to get context attribute SearchIndexExcludes /* try to get context attribute SearchIndexExcludes
* and use that as the start of the list of exclude * and use that as the start of the list of exclude
* objects. This allows other ContextListeners to add to * objects. This allows other ContextListeners to add to
* the basic set of SearchIndexExcludes . */ * the basic set of SearchIndexExcludes . */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<SearchIndexExcluder> excludes = List<SearchIndexExcluder> searchIndexExcludesFromContext =
(List<SearchIndexExcluder>)context.getAttribute("SearchIndexExcludes"); (List<SearchIndexExcluder>)context.getAttribute("SearchIndexExcludes");
if( excludes == null )
excludes = new ArrayList<SearchIndexExcluder>();
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 = IndividualToSolrDocument indToSolrDoc =
new IndividualToSolrDocument(excludes, modifiers); setupTransltion(jenaOntModel, displayModel,
RDFServiceUtils.getRDFServiceFactory(context),
modifiersFromContext,
searchIndexExcludesFromContext);
/* setup solr indexer */ /* setup solr indexer */
SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc); SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc);
@ -213,4 +203,44 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
return (SolrServer) ctx.getAttribute(SOLR_SERVER); return (SolrServer) ctx.getAttribute(SOLR_SERVER);
} }
public static IndividualToSolrDocument setupTransltion(
OntModel jenaOntModel,
Model displayModel,
RDFServiceFactory rdfServiceFactory,
List<DocumentModifier> modifiersFromContext,
List<SearchIndexExcluder> 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<DocumentModifier> modifiers = new ArrayList<DocumentModifier>();
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<SearchIndexExcluder> excludes =
new ArrayList<SearchIndexExcluder>();
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);
}
} }

View file

@ -7,23 +7,18 @@ import java.util.Iterator;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.solr.common.SolrInputDocument; 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.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap; import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; 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.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; 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.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; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
public class ThumbnailImageURL implements DocumentModifier { public class ThumbnailImageURL implements DocumentModifier {
@ -44,15 +39,15 @@ public class ThumbnailImageURL implements DocumentModifier {
" ?a <http://vitro.mannlib.cornell.edu/ns/vitro/public#downloadLocation> ?downloadLocation . } " ; " ?a <http://vitro.mannlib.cornell.edu/ns/vitro/public#downloadLocation> ?downloadLocation . } " ;
//" ?b <http://vitro.mannlib.cornell.edu/ns/vitro/public#directDownloadUrl> ?thumbnailLocationURL . } "; //" ?b <http://vitro.mannlib.cornell.edu/ns/vitro/public#directDownloadUrl> ?thumbnailLocationURL . } ";
private Model model; private RDFServiceFactory rsf;
private Log log = LogFactory.getLog(ThumbnailImageURL.class); private Log log = LogFactory.getLog(ThumbnailImageURL.class);
static VitroSearchTermNames term = new VitroSearchTermNames(); static VitroSearchTermNames term = new VitroSearchTermNames();
String fieldForThumbnailURL = term.THUMBNAIL_URL; String fieldForThumbnailURL = term.THUMBNAIL_URL;
public ThumbnailImageURL(Model model){ public ThumbnailImageURL( RDFServiceFactory rsf ){
this.model = model; this.rsf = rsf;
} }
@Override @Override
@ -85,12 +80,9 @@ public class ThumbnailImageURL implements DocumentModifier {
Resource uriResource = ResourceFactory.createResource(individual.getURI()); Resource uriResource = ResourceFactory.createResource(individual.getURI());
initialBinding.add("uri", uriResource); initialBinding.add("uri", uriResource);
Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ); RDFService rdf = rsf.getRDFService();
model.getLock().enterCriticalSection(Lock.READ);
try{ try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, model, initialBinding); ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, rdf);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){ while(results.hasNext()){
QuerySolution soln = results.nextSolution(); QuerySolution soln = results.nextSolution();
Iterator<String> iter = soln.varNames() ; Iterator<String> iter = soln.varNames() ;
@ -107,12 +99,8 @@ public class ThumbnailImageURL implements DocumentModifier {
}catch(Throwable t){ }catch(Throwable t){
log.error(t,t); log.error(t,t);
} finally{ } finally{
qExec.close(); rdf.close();
} }
}finally{
model.getLock().leaveCriticalSection();
}
return result.toString(); return result.toString();
} }