Merging changes from 1.3 maint.

This commit is contained in:
briancaruso 2011-07-28 22:32:25 +00:00
parent fa8b6db07e
commit 3a3aa5656b
8 changed files with 85 additions and 14 deletions

View file

@ -22,4 +22,8 @@ public interface StatementToURIsToUpdate {
* @return List of URIs. * @return List of URIs.
*/ */
List<String> findAdditionalURIsToIndex(Statement stmt); List<String> findAdditionalURIsToIndex(Statement stmt);
void startIndexing();
void endIndxing();
} }

View file

@ -63,4 +63,9 @@ public class AdditionalURIsForClassGroupChanges implements
} }
} }
@Override
public void startIndexing() { /* nothing to prepare */ }
@Override
public void endIndxing() { /* nothing to do */ }
} }

View file

@ -4,8 +4,10 @@ package edu.cornell.mannlib.vitro.webapp.search.indexing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -30,6 +32,9 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate;
public class AdditionalURIsForContextNodes implements StatementToURIsToUpdate { public class AdditionalURIsForContextNodes implements StatementToURIsToUpdate {
private OntModel model; private OntModel model;
private Set<String> alreadyChecked;
private long accumulatedTime = 0;
private static final List<String> multiValuedQueriesForAgent = new ArrayList<String>(); private static final List<String> multiValuedQueriesForAgent = new ArrayList<String>();
private static final String multiValuedQueryForInformationResource; private static final String multiValuedQueryForInformationResource;
private static final List<String> multiValuedQueriesForRole = new ArrayList<String>(); private static final List<String> multiValuedQueriesForRole = new ArrayList<String>();
@ -46,26 +51,44 @@ public class AdditionalURIsForContextNodes implements StatementToURIsToUpdate {
public List<String> findAdditionalURIsToIndex(Statement stmt) { public List<String> findAdditionalURIsToIndex(Statement stmt) {
if( stmt != null ){ if( stmt != null ){
long start = System.currentTimeMillis();
List<String>urisToIndex = new ArrayList<String>(); List<String>urisToIndex = new ArrayList<String>();
if(stmt.getSubject() != null && stmt.getSubject().isURIResource() ){ if(stmt.getSubject() != null && stmt.getSubject().isURIResource() ){
String subjUri = stmt.getSubject().getURI(); String subjUri = stmt.getSubject().getURI();
if( subjUri != null){ if( subjUri != null && ! alreadyChecked.contains( subjUri )){
urisToIndex.addAll( findAdditionalURIsToIndex(subjUri)); urisToIndex.addAll( findAdditionalURIsToIndex(subjUri));
alreadyChecked.add(subjUri);
} }
} }
if( stmt.getObject() != null && stmt.getObject().isURIResource() ){ if( stmt.getObject() != null && stmt.getObject().isURIResource() ){
String objUri = stmt.getSubject().getURI(); String objUri = stmt.getSubject().getURI();
if( objUri != null){ if( objUri != null && ! alreadyChecked.contains(objUri)){
urisToIndex.addAll( findAdditionalURIsToIndex(objUri)); urisToIndex.addAll( findAdditionalURIsToIndex(objUri));
alreadyChecked.add(objUri);
} }
} }
accumulatedTime += (System.currentTimeMillis() - start ) ;
return urisToIndex; return urisToIndex;
}else{ }else{
return Collections.emptyList(); 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) { protected List<String> findAdditionalURIsToIndex(String uri) {
List<String> uriList = new ArrayList<String>(); List<String> uriList = new ArrayList<String>();

View file

@ -19,4 +19,9 @@ public class AdditionalURIsForDataProperties implements StatementToURIsToUpdate
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public void startIndexing() { /* nothing to prepare */ }
@Override
public void endIndxing() { /* nothing to do */ }
} }

View file

@ -55,6 +55,12 @@ public class AdditionalURIsForObjectProperties implements StatementToURIsToUpdat
return doObjectPropertyStmt( stmt ); return doObjectPropertyStmt( stmt );
} }
@Override
public void startIndexing() { /* nothing to prepare */ }
@Override
public void endIndxing() { /* nothing to do */ }
protected List<String> doObjectPropertyStmt(Statement stmt) { protected List<String> doObjectPropertyStmt(Statement stmt) {
// Only need to consider the object since the subject // Only need to consider the object since the subject
// will already be updated in search index as part of // will already be updated in search index as part of
@ -141,4 +147,6 @@ public class AdditionalURIsForObjectProperties implements StatementToURIsToUpdat
" ?uri ?p ?related \n " + " ?uri ?p ?related \n " +
" filter( isURI( ?related ) && ?p != rdf:type ) \n" + " filter( isURI( ?related ) && ?p != rdf:type ) \n" +
"}" ; "}" ;
} }

View file

@ -26,4 +26,11 @@ public class AdditionalURIsForTypeStatements implements StatementToURIsToUpdate
} }
} }
@Override
public void startIndexing() { /* nothing to prepare */ }
@Override
public void endIndxing() { /* nothing to do */ }
} }

View file

@ -227,6 +227,10 @@ public class IndexBuilder extends Thread {
* the index. * the index.
*/ */
private Collection<String> statementsToUris( Collection<Statement> localChangedStmt ){ 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>(); Collection<String> urisToUpdate = new HashSet<String>();
for( Statement stmt : localChangedStmt){ for( Statement stmt : localChangedStmt){
if( stmt == null ) if( stmt == null )
@ -235,6 +239,11 @@ public class IndexBuilder extends Thread {
urisToUpdate.addAll( stu.findAdditionalURIsToIndex(stmt) ); urisToUpdate.addAll( stu.findAdditionalURIsToIndex(stmt) );
} }
} }
//inform StatementToURIsToUpdate that they are done
for( StatementToURIsToUpdate stu : stmtToURIsToIndexFunctions )
stu.endIndxing();
return urisToUpdate; return urisToUpdate;
} }

View file

@ -109,14 +109,11 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
wadf = new WebappDaoFactoryFiltering(wadf, vf); wadf = new WebappDaoFactoryFiltering(wadf, vf);
// make objects that will find additional URIs for context nodes etc // make objects that will find additional URIs for context nodes etc
List<StatementToURIsToUpdate> uriFinders = new ArrayList<StatementToURIsToUpdate>(); List<StatementToURIsToUpdate> uriFinders = makeURIFinders(jenaOntModel);
uriFinders.add( new AdditionalURIsForDataProperties() );
uriFinders.add( new AdditionalURIsForObjectProperties(jenaOntModel) );
uriFinders.add( new AdditionalURIsForContextNodes(jenaOntModel) );
uriFinders.add( new AdditionalURIsForTypeStatements() );
// Make the IndexBuilder
IndexBuilder builder = new IndexBuilder( solrIndexer, wadf, uriFinders ); 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); context.setAttribute(IndexBuilder.class.getName(), builder);
// set up listeners so search index builder is notified of changes to model // 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 @Override
public void contextDestroyed(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent sce) {