diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/StatementToURIsToUpdate.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/StatementToURIsToUpdate.java index 8360f6639..a0fbe3c6d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/StatementToURIsToUpdate.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/StatementToURIsToUpdate.java @@ -22,4 +22,8 @@ public interface StatementToURIsToUpdate { * @return List of URIs. */ List findAdditionalURIsToIndex(Statement stmt); + + void startIndexing(); + + void endIndxing(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForClassGroupChanges.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForClassGroupChanges.java index cd6618bd1..c52958a3d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForClassGroupChanges.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForClassGroupChanges.java @@ -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 */ } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java index e544b732a..06dfad192 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java @@ -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 multiValuedQueriesForAgent = new ArrayList(); + private Set alreadyChecked; + private long accumulatedTime = 0; + + private static final List multiValuedQueriesForAgent = new ArrayList(); private static final String multiValuedQueryForInformationResource; private static final List multiValuedQueriesForRole = new ArrayList(); - private static final ListqueryList; + private static final ListqueryList; private Log log = LogFactory.getLog(AdditionalURIsForContextNodes.class); public AdditionalURIsForContextNodes( OntModel jenaOntModel){ - this.model = jenaOntModel; + this.model = jenaOntModel; } @Override public List findAdditionalURIsToIndex(Statement stmt) { if( stmt != null ){ + long start = System.currentTimeMillis(); + ListurisToIndex = new ArrayList(); 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(); + accumulatedTime = 0L; + } + + @Override + public void endIndxing() { + log.debug( "Accumulated time for this run of the index: " + accumulatedTime + " msec"); + alreadyChecked = null; + } + protected List findAdditionalURIsToIndex(String uri) { List uriList = new ArrayList(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForDataProperties.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForDataProperties.java index ef08177b1..d9528aa0d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForDataProperties.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForDataProperties.java @@ -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 */ } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForObjectProperties.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForObjectProperties.java index 95d702768..ba6d6d1e8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForObjectProperties.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForObjectProperties.java @@ -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 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" + - "}" ; + "}" ; + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForTypeStatements.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForTypeStatements.java index 0be6a2834..7103f48c4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForTypeStatements.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForTypeStatements.java @@ -26,4 +26,11 @@ public class AdditionalURIsForTypeStatements implements StatementToURIsToUpdate } } + @Override + public void startIndexing() { /* nothing to prepare */ } + + @Override + public void endIndxing() { /* nothing to do */ } + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index e22928839..a96539916 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -227,6 +227,10 @@ public class IndexBuilder extends Thread { * the index. */ private Collection statementsToUris( Collection localChangedStmt ){ + //inform StatementToURIsToUpdate that index is starting + for( StatementToURIsToUpdate stu : stmtToURIsToIndexFunctions ) + stu.startIndexing(); + Collection urisToUpdate = new HashSet(); 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; } 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 f6674df6f..506b96dde 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 @@ -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 uriFinders = new ArrayList(); - 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 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 makeURIFinders( OntModel jenaOntModel ){ + List uriFinders = new ArrayList(); + 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) {