Merging changes from 1.3 maint.
This commit is contained in:
parent
fa8b6db07e
commit
3a3aa5656b
8 changed files with 85 additions and 14 deletions
|
@ -22,4 +22,8 @@ public interface StatementToURIsToUpdate {
|
|||
* @return List of URIs.
|
||||
*/
|
||||
List<String> findAdditionalURIsToIndex(Statement stmt);
|
||||
|
||||
void startIndexing();
|
||||
|
||||
void endIndxing();
|
||||
}
|
||||
|
|
|
@ -62,5 +62,10 @@ public class AdditionalURIsForClassGroupChanges implements
|
|||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIndexing() { /* nothing to prepare */ }
|
||||
|
||||
@Override
|
||||
public void endIndxing() { /* nothing to do */ }
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ package edu.cornell.mannlib.vitro.webapp.search.indexing;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -30,42 +32,63 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate;
|
|||
public class AdditionalURIsForContextNodes implements StatementToURIsToUpdate {
|
||||
|
||||
private OntModel model;
|
||||
private static final List<String> multiValuedQueriesForAgent = new ArrayList<String>();
|
||||
private Set<String> alreadyChecked;
|
||||
private long accumulatedTime = 0;
|
||||
|
||||
private static final List<String> multiValuedQueriesForAgent = new ArrayList<String>();
|
||||
private static final String multiValuedQueryForInformationResource;
|
||||
private static final List<String> multiValuedQueriesForRole = new ArrayList<String>();
|
||||
private static final List<String>queryList;
|
||||
private static final List<String>queryList;
|
||||
|
||||
private Log log = LogFactory.getLog(AdditionalURIsForContextNodes.class);
|
||||
|
||||
|
||||
public AdditionalURIsForContextNodes( OntModel jenaOntModel){
|
||||
this.model = jenaOntModel;
|
||||
this.model = jenaOntModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findAdditionalURIsToIndex(Statement stmt) {
|
||||
|
||||
if( stmt != null ){
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
List<String>urisToIndex = new ArrayList<String>();
|
||||
if(stmt.getSubject() != null && stmt.getSubject().isURIResource() ){
|
||||
String subjUri = stmt.getSubject().getURI();
|
||||
if( subjUri != null){
|
||||
if( subjUri != null && ! alreadyChecked.contains( subjUri )){
|
||||
urisToIndex.addAll( findAdditionalURIsToIndex(subjUri));
|
||||
alreadyChecked.add(subjUri);
|
||||
}
|
||||
}
|
||||
|
||||
if( stmt.getObject() != null && stmt.getObject().isURIResource() ){
|
||||
String objUri = stmt.getSubject().getURI();
|
||||
if( objUri != null){
|
||||
if( objUri != null && ! alreadyChecked.contains(objUri)){
|
||||
urisToIndex.addAll( findAdditionalURIsToIndex(objUri));
|
||||
alreadyChecked.add(objUri);
|
||||
}
|
||||
}
|
||||
|
||||
accumulatedTime += (System.currentTimeMillis() - start ) ;
|
||||
return urisToIndex;
|
||||
}else{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIndexing() {
|
||||
alreadyChecked = new HashSet<String>();
|
||||
accumulatedTime = 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endIndxing() {
|
||||
log.debug( "Accumulated time for this run of the index: " + accumulatedTime + " msec");
|
||||
alreadyChecked = null;
|
||||
}
|
||||
|
||||
protected List<String> findAdditionalURIsToIndex(String uri) {
|
||||
|
||||
List<String> uriList = new ArrayList<String>();
|
||||
|
|
|
@ -19,4 +19,9 @@ public class AdditionalURIsForDataProperties implements StatementToURIsToUpdate
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIndexing() { /* nothing to prepare */ }
|
||||
|
||||
@Override
|
||||
public void endIndxing() { /* nothing to do */ }
|
||||
}
|
||||
|
|
|
@ -55,6 +55,12 @@ public class AdditionalURIsForObjectProperties implements StatementToURIsToUpdat
|
|||
return doObjectPropertyStmt( stmt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIndexing() { /* nothing to prepare */ }
|
||||
|
||||
@Override
|
||||
public void endIndxing() { /* nothing to do */ }
|
||||
|
||||
protected List<String> doObjectPropertyStmt(Statement stmt) {
|
||||
// Only need to consider the object since the subject
|
||||
// will already be updated in search index as part of
|
||||
|
@ -140,5 +146,7 @@ public class AdditionalURIsForObjectProperties implements StatementToURIsToUpdat
|
|||
"SELECT ?related WHERE { \n" +
|
||||
" ?uri ?p ?related \n " +
|
||||
" filter( isURI( ?related ) && ?p != rdf:type ) \n" +
|
||||
"}" ;
|
||||
"}" ;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,4 +26,11 @@ public class AdditionalURIsForTypeStatements implements StatementToURIsToUpdate
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIndexing() { /* nothing to prepare */ }
|
||||
|
||||
@Override
|
||||
public void endIndxing() { /* nothing to do */ }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -227,6 +227,10 @@ public class IndexBuilder extends Thread {
|
|||
* the index.
|
||||
*/
|
||||
private Collection<String> statementsToUris( Collection<Statement> localChangedStmt ){
|
||||
//inform StatementToURIsToUpdate that index is starting
|
||||
for( StatementToURIsToUpdate stu : stmtToURIsToIndexFunctions )
|
||||
stu.startIndexing();
|
||||
|
||||
Collection<String> urisToUpdate = new HashSet<String>();
|
||||
for( Statement stmt : localChangedStmt){
|
||||
if( stmt == null )
|
||||
|
@ -234,7 +238,12 @@ public class IndexBuilder extends Thread {
|
|||
for( StatementToURIsToUpdate stu : stmtToURIsToIndexFunctions ){
|
||||
urisToUpdate.addAll( stu.findAdditionalURIsToIndex(stmt) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//inform StatementToURIsToUpdate that they are done
|
||||
for( StatementToURIsToUpdate stu : stmtToURIsToIndexFunctions )
|
||||
stu.endIndxing();
|
||||
|
||||
return urisToUpdate;
|
||||
}
|
||||
|
||||
|
|
|
@ -108,15 +108,12 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
|
|||
VitroFilters vf = VitroFilterUtils.getPublicFilter(context);
|
||||
wadf = new WebappDaoFactoryFiltering(wadf, vf);
|
||||
|
||||
//make objects that will find additional URIs for context nodes etc
|
||||
List<StatementToURIsToUpdate> uriFinders = new ArrayList<StatementToURIsToUpdate>();
|
||||
uriFinders.add( new AdditionalURIsForDataProperties() );
|
||||
uriFinders.add( new AdditionalURIsForObjectProperties(jenaOntModel) );
|
||||
uriFinders.add( new AdditionalURIsForContextNodes(jenaOntModel) );
|
||||
uriFinders.add( new AdditionalURIsForTypeStatements() );
|
||||
// make objects that will find additional URIs for context nodes etc
|
||||
List<StatementToURIsToUpdate> uriFinders = makeURIFinders(jenaOntModel);
|
||||
|
||||
// Make the IndexBuilder
|
||||
IndexBuilder builder = new IndexBuilder( solrIndexer, wadf, uriFinders );
|
||||
// to the servlet context so we can access it later in the webapp.
|
||||
// Save it to the servlet context so we can access it later in the webapp.
|
||||
context.setAttribute(IndexBuilder.class.getName(), builder);
|
||||
|
||||
// set up listeners so search index builder is notified of changes to model
|
||||
|
@ -131,6 +128,19 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a list of StatementToURIsToUpdate objects for use by the
|
||||
* IndexBuidler.
|
||||
*/
|
||||
public List<StatementToURIsToUpdate> makeURIFinders( OntModel jenaOntModel ){
|
||||
List<StatementToURIsToUpdate> uriFinders = new ArrayList<StatementToURIsToUpdate>();
|
||||
uriFinders.add( new AdditionalURIsForDataProperties() );
|
||||
uriFinders.add( new AdditionalURIsForObjectProperties(jenaOntModel) );
|
||||
uriFinders.add( new AdditionalURIsForContextNodes(jenaOntModel) );
|
||||
uriFinders.add( new AdditionalURIsForTypeStatements() );
|
||||
return uriFinders;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue