From 54e6abd53b7644269c4f6af749ea031be03b1cab Mon Sep 17 00:00:00 2001 From: bdc34 Date: Wed, 26 Jan 2011 17:11:25 +0000 Subject: [PATCH] Improved performance of lucene index build under SDB. NIHVIVO-1795 --- .../vitro/webapp/beans/Individual.java | 1 + .../vitro/webapp/beans/IndividualImpl.java | 4 + .../dao/filtering/IndividualFiltering.java | 6 + .../vitro/webapp/dao/jena/IndividualSDB.java | 137 ++++++++++++++---- .../search/lucene/Entity2LuceneDoc.java | 4 +- 5 files changed, 123 insertions(+), 29 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java index bc299f87d..7fd075d3e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java @@ -115,6 +115,7 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com String getImageUrl(); String getThumbUrl(); + boolean hasThumb(); String getUrl(); void setUrl(String url); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java index 876887396..c6fd97c76 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java @@ -501,4 +501,8 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp return getURI() + " " + getName(); } } + + public boolean hasThumb() { + return getThumbUrl() != null && ! getThumbUrl().isEmpty(); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java index 537dd9e9f..f7129554f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java @@ -646,4 +646,10 @@ public class IndividualFiltering implements Individual { // Since the statements have been filtered, we can just take the first individual without filtering. return stmts.isEmpty() ? null : stmts.get(0).getObject(); } + + + @Override + public boolean hasThumb() { + return _innerIndividual.hasThumb(); + } } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index 93422002b..d7c855406 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -71,6 +71,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { SDBDatasetMode.ASSERTIONS_AND_INFERENCES; private String individualURI = null; private Model model = null; + private Boolean _hasThumb = null; public IndividualSDB(String individualURI, DatasetWrapperFactory datasetWrapperFactory, @@ -431,39 +432,92 @@ public class IndividualSDB extends IndividualImpl implements Individual { } - public Date getSunrise() { - if (sunrise != null) { - return sunrise; - } else { - constructProperty(ind, VitroVocabulary.SUNRISE); - ind.getOntModel().enterCriticalSection(Lock.READ); - try { - sunrise = webappDaoFactory.getJenaBaseDao() - .getPropertyDateTimeValue( - ind,webappDaoFactory.getJenaBaseDao().SUNRISE); - return sunrise; - } finally { - ind.getOntModel().leaveCriticalSection(); + public Date getSunrise() { + if( this.sunrise == null ){ + String[] graphVars = { "?g" }; + String getPropertyValue = + "SELECT ?value" + + "WHERE { GRAPH ?g { <" + individualURI + "> " + + "<" + webappDaoFactory.getJenaBaseDao().SUNRISE + "> " + + "?value} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try{ + sunrise =(Date) + ((Literal)QueryExecutionFactory.create(QueryFactory.create(getPropertyValue), dataset) + .execSelect()).getValue(); + }catch(Exception ex){ + log.error("could not get sunrise: " + ex.getMessage(),ex); + }finally{ + dataset.getLock().leaveCriticalSection(); + w.close(); } } + + return sunrise; + +// if (sunrise != null) { +// return sunrise; +// } else { +// constructProperty(ind, VitroVocabulary.SUNRISE); +// ind.getOntModel().enterCriticalSection(Lock.READ); +// try { +// sunrise = webappDaoFactory.getJenaBaseDao() +// .getPropertyDateTimeValue( +// ind,webappDaoFactory.getJenaBaseDao().SUNRISE); +// return sunrise; +// } finally { +// ind.getOntModel().leaveCriticalSection(); +// } +// } } - public Date getSunset() { - if (sunset != null) { - return sunset; - } else { - constructProperty(ind, VitroVocabulary.SUNSET); - ind.getOntModel().enterCriticalSection(Lock.READ); - try { - sunset = webappDaoFactory.getJenaBaseDao() - .getPropertyDateTimeValue( - ind,webappDaoFactory.getJenaBaseDao().SUNSET); - return sunset; - } finally { - - ind.getOntModel().leaveCriticalSection(); + public Date getSunset() { + + if( this.sunset == null ){ + String[] graphVars = { "?g" }; + String getPropertyValue = + "SELECT ?value" + + "WHERE { GRAPH ?g { <" + individualURI + "> " + + "<"+webappDaoFactory.getJenaBaseDao().SUNSET+"> " + + "?value} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try{ + sunset =(Date) + ((Literal)QueryExecutionFactory.create(QueryFactory.create(getPropertyValue), dataset) + .execSelect()).getValue(); + }catch(Exception ex){ + log.error("could not get sunset: " + ex.getMessage(),ex); + }finally{ + dataset.getLock().leaveCriticalSection(); + w.close(); } } + + return sunset; + +// if (sunset != null) { +// return sunset; +// } else { +// constructProperty(ind, VitroVocabulary.SUNSET); +// ind.getOntModel().enterCriticalSection(Lock.READ); +// try { +// sunset = webappDaoFactory.getJenaBaseDao() +// .getPropertyDateTimeValue( +// ind,webappDaoFactory.getJenaBaseDao().SUNSET); +// return sunset; +// } finally { +// +// ind.getOntModel().leaveCriticalSection(); +// } +// } } public Date getTimekey() { @@ -691,6 +745,35 @@ public class IndividualSDB extends IndividualImpl implements Individual { return this.imageInfo.getThumbnail().getBytestreamAliasUrl(); } + @Override + public boolean hasThumb(){ + if( _hasThumb != null ){ + return _hasThumb; + }else{ + String[] graphVars = { "?g" }; + String ask = + "ASK { GRAPH ?g " + + " { <" + individualURI + "> ?mainImage . \n" + + " ?mainImage ?thumbImage . }\n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try{ + _hasThumb = QueryExecutionFactory.create(QueryFactory.create(ask), dataset).execAsk(); + }catch(Exception ex){ + _hasThumb = false; + log.error(ex,ex); + }finally{ + dataset.getLock().leaveCriticalSection(); + w.close(); + } + return _hasThumb; + } + } + + public String getAnchor() { if (this.anchor != null) { return anchor; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java index 9063ca7f9..e898a4901 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java @@ -221,7 +221,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{ try{ value = null; - if( ent.getThumbUrl() != null ) + if( ent.hasThumb() ) doc.add(new Field(term.THUMBNAIL, "1", Field.Store.YES, Field.Index.NOT_ANALYZED)); else doc.add(new Field(term.THUMBNAIL, "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); @@ -238,7 +238,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{ doPortalFlags(ent, doc); //do flag 2 legacy, only used at Cornell - doFlag2( ent, doc ); + //doFlag2( ent, doc ); //ALLTEXT, all of the 'full text' String t=null;