Changes to Solr indexing building.
Added method to SolrSetup to make IndividualToSolrDocument. Changed ThumbnailImageURL to use RDFServiceFactory.
This commit is contained in:
parent
ac85ebf8c8
commit
8f8e9762f8
2 changed files with 80 additions and 62 deletions
|
@ -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;
|
||||
|
@ -127,33 +128,22 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
|
|||
* objects. This allows other ContextListeners to add to
|
||||
* the basic set of DocumentModifiers. */
|
||||
@SuppressWarnings("unchecked")
|
||||
List<DocumentModifier> modifiers =
|
||||
List<DocumentModifier> modifiersFromContext =
|
||||
(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
|
||||
* 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<SearchIndexExcluder> excludes =
|
||||
List<SearchIndexExcluder> searchIndexExcludesFromContext =
|
||||
(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 =
|
||||
new IndividualToSolrDocument(excludes, modifiers);
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <http://vitro.mannlib.cornell.edu/ns/vitro/public#downloadLocation> ?downloadLocation . } " ;
|
||||
//" ?b <http://vitro.mannlib.cornell.edu/ns/vitro/public#directDownloadUrl> ?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
|
||||
|
@ -85,12 +80,9 @@ public class ThumbnailImageURL implements DocumentModifier {
|
|||
Resource uriResource = ResourceFactory.createResource(individual.getURI());
|
||||
initialBinding.add("uri", uriResource);
|
||||
|
||||
Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ);
|
||||
model.getLock().enterCriticalSection(Lock.READ);
|
||||
RDFService rdf = rsf.getRDFService();
|
||||
try{
|
||||
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, model, initialBinding);
|
||||
try{
|
||||
ResultSet results = qExec.execSelect();
|
||||
ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, rdf);
|
||||
while(results.hasNext()){
|
||||
QuerySolution soln = results.nextSolution();
|
||||
Iterator<String> iter = soln.varNames() ;
|
||||
|
@ -107,12 +99,8 @@ public class ThumbnailImageURL implements DocumentModifier {
|
|||
}catch(Throwable t){
|
||||
log.error(t,t);
|
||||
} finally{
|
||||
qExec.close();
|
||||
rdf.close();
|
||||
}
|
||||
}finally{
|
||||
model.getLock().leaveCriticalSection();
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue