diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java index 97d032915..d43c4e48b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java @@ -13,6 +13,7 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.Dataset; +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.rdf.model.Model; @@ -74,9 +75,12 @@ public class ObjectPropertyStatementDaoSDB extends DatasetWrapper w = dwf.getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); + QueryExecution qexec = null; try { - m = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); + qexec = QueryExecutionFactory.create(QueryFactory.create(query), dataset); + m = qexec.execConstruct(); } finally { + if(qexec != null) qexec.close(); dataset.getLock().leaveCriticalSection(); w.close(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index f19d8b892..50d4ff344 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -133,6 +133,11 @@ public class VitroRequestPrep implements Filter { //This will replace the WebappDaoFactory with a different version if menu management parameter is found wdf = checkForSpecialWDF(vreq, wdf); + // request.setAttribute("aboxModel", setspeicalABoxModel) + // request.setAttribute("tboxModel", speicalTboxModel) + // request.setAttribute("infModel", speicalInfModel) (maybe?) + // request.setAttribute("displayModel", displayModel) + VitroFilters filters = null; filters = getFiltersFromContextFilterFactory(req, wdf); 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 546687769..1bff5ffb1 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 @@ -146,6 +146,7 @@ public class IndexBuilder extends Thread { } } + indexer.abortIndexingAndCleanUp(); if(log != null )//may be null on shutdown log.info("Stopping IndexBuilder thread"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java index c067ab7e8..0b09b737d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java @@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class CalculateParameters implements DocumentModifier { + private boolean shutdown = false; private Dataset dataset; public static int totalInd=1; protected Map betaMap = new Hashtable(); @@ -90,11 +91,11 @@ public class CalculateParameters implements DocumentModifier { QuerySolution soln = null; Resource uriResource = ResourceFactory.createResource(uri); initialBinding.add("uri", uriResource); - dataset.getLock().enterCriticalSection(Lock.READ); - + dataset.getLock().enterCriticalSection(Lock.READ); + QueryExecution qexec=null; try{ query = QueryFactory.create(betaQuery,Syntax.syntaxARQ); - QueryExecution qexec = QueryExecutionFactory.create(query,dataset,initialBinding); + qexec = QueryExecutionFactory.create(query,dataset,initialBinding); ResultSet results = qexec.execSelect(); List resultVars = results.getResultVars(); if(resultVars!=null && resultVars.size()!=0){ @@ -102,8 +103,11 @@ public class CalculateParameters implements DocumentModifier { Conn = Integer.parseInt(soln.getLiteral(resultVars.get(0)).getLexicalForm()); } }catch(Throwable t){ - log.error(t,t); + if( ! shutdown ) + log.error(t,t); }finally{ + if( qexec != null ) + qexec.close(); dataset.getLock().leaveCriticalSection(); } @@ -238,7 +242,8 @@ public class CalculateParameters implements DocumentModifier { } } }catch(Exception e){ - log.error("Error found in getAdjacentNodes method of SearchQueryHandler"); + if( ! shutdown ) + log.error("Error found in getAdjacentNodes method of SearchQueryHandler"); }finally{ qexec.close(); } @@ -260,7 +265,8 @@ public class CalculateParameters implements DocumentModifier { } catch(Throwable t){ - log.error(t,t); + if( ! shutdown ) + log.error(t,t); }finally{ dataset.getLock().leaveCriticalSection(); adjacentNodes = null; @@ -285,18 +291,21 @@ public class CalculateParameters implements DocumentModifier { for(String term: fieldsToAddBetaTo){ SolrInputField f = doc.getField( term ); - f.setBoost( getBeta(uri) + phi + IndividualToSolrDocument.NAME_BOOST); + float orgBoost = f.getBoost(); + f.setBoost( getBeta(uri) + phi + orgBoost ); } for(String term: fieldsToMultiplyBetaBy){ SolrInputField f = doc.getField( term ); - f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); + //f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); } - SolrInputField f = doc.getField(VitroSearchTermNames.targetInfo); - f.addValue(adjInfo[1],f.getBoost()); - doc.setDocumentBoost(getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); - + + //SolrInputField f = doc.getField(VitroSearchTermNames.targetInfo); + //f.addValue(adjInfo[1],f.getBoost()); + + doc.setDocumentBoost(getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); + log.debug("Parameter calculation is done"); } @@ -304,6 +313,9 @@ public class CalculateParameters implements DocumentModifier { betaMap.clear(); } + public void shutdown(){ + shutdown=true; + } } class TotalInd implements Runnable{ @@ -321,10 +333,11 @@ class TotalInd implements Runnable{ Query query; QuerySolution soln = null; dataset.getLock().enterCriticalSection(Lock.READ); + QueryExecution qexec = null; try{ query = QueryFactory.create(totalCountQuery,Syntax.syntaxARQ); - QueryExecution qexec = QueryExecutionFactory.create(query,dataset); + qexec = QueryExecutionFactory.create(query,dataset); ResultSet results = qexec.execSelect(); List resultVars = results.getResultVars(); @@ -337,8 +350,12 @@ class TotalInd implements Runnable{ }catch(Throwable t){ log.error(t,t); }finally{ + if( qexec != null ) + qexec.close(); dataset.getLock().leaveCriticalSection(); } } + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java index 5d6ea4f44..6e7d9dd2d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java @@ -35,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class ContextNodeFields implements DocumentModifier{ private Model model; + private boolean shutdown = false; private static ExecutorService threadPool = null; private static final int THREAD_POOL_SIZE = 10; @@ -134,7 +135,8 @@ public class ContextNodeFields implements DocumentModifier{ } } }catch(Throwable t){ - log.error(t,t); + if( ! shutdown ) + log.error(t,t); } finally{ qExec.close(); } @@ -436,5 +438,8 @@ public class ContextNodeFields implements DocumentModifier{ return new Thread( getNewThreadName() ); } } - + + public void shutdown(){ + shutdown=true; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/DocumentModifier.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/DocumentModifier.java index 4a7bcf100..f1d97270a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/DocumentModifier.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/DocumentModifier.java @@ -11,5 +11,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; */ public interface DocumentModifier { public void modifyDocument(Individual individual, SolrInputDocument doc, StringBuffer addUri); + + //called to inform the DocumentModifier that the system is shutting down + public void shutdown(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java index 6e36f3068..54628dc94 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java @@ -315,6 +315,17 @@ public class IndividualToSolrDocument { return ent; } + public void shutdown(){ + for(DocumentModifier dm: documentModifiers){ + try{ + dm.shutdown(); + }catch(Exception e){ + if( log != null) + log.debug(e,e); + } + } + } + private void fillContextNodes(){ IndividualToSolrDocument.contextNodeClassNames.add("Role"); IndividualToSolrDocument.contextNodeClassNames.add("AttendeeRole"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java index 948f0fdaa..b8dfea16a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java @@ -158,32 +158,51 @@ public class SolrIndexer implements IndexerIface { @Override public void abortIndexingAndCleanUp() { - endIndexing(); + try{ + server.commit(); + }catch(SolrServerException e){ + if( log != null) + log.debug("could not commit to solr server, " + + "this should not be a problem since solr will do autocommit"); + } catch (IOException e) { + if( log != null) + log.debug("could not commit to solr server, " + + "this should not be a problem since solr will do autocommit"); + } + try{ + individualToSolrDoc.shutdown(); + }catch(Exception e){ + if( log != null) + log.warn(e,e); + } } + @Override public synchronized void endIndexing() { try { - UpdateResponse res = server.commit(); - log.debug("Response after committing to server: "+ res ); - } catch (SolrServerException e) { - log.error("Could not commit to solr server", e); - } catch(IOException e){ - log.error("Could not commit to solr server", e); - }finally{ - if(!individualToSolrDoc.documentModifiers.isEmpty()){ - if(individualToSolrDoc.documentModifiers.get(0) instanceof CalculateParameters){ - CalculateParameters c = (CalculateParameters) individualToSolrDoc.documentModifiers.get(0); - c.clearMap(); - log.info("BetaMap cleared"); - } - } - } + UpdateResponse res = server.commit(); + log.debug("Response after committing to server: "+ res ); + } catch (SolrServerException e) { + log.error("Could not commit to solr server", e); + } catch(IOException e){ + log.error("Could not commit to solr server", e); + }finally{ + if(!individualToSolrDoc.documentModifiers.isEmpty()){ + if(individualToSolrDoc.documentModifiers.get(0) instanceof CalculateParameters){ + CalculateParameters c = (CalculateParameters) individualToSolrDoc.documentModifiers.get(0); + c.clearMap(); + log.info("BetaMap cleared"); + } + } + } + try { server.optimize(); } catch (Exception e) { log.error("Could not optimize solr server", e); } + indexing = false; notifyAll(); } @@ -215,8 +234,4 @@ public class SolrIndexer implements IndexerIface { return false; } - - - - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java index 1677b513f..3b77d219a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -563,7 +563,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel return TYPE; } - public String getTemplate() { + public String Template() { return config.templateName; }