Improved performance of lucene index build under SDB. NIHVIVO-1795

This commit is contained in:
bdc34 2011-01-26 17:11:25 +00:00
parent b321fc38c9
commit 54e6abd53b
5 changed files with 123 additions and 29 deletions

View file

@ -115,6 +115,7 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com
String getImageUrl(); String getImageUrl();
String getThumbUrl(); String getThumbUrl();
boolean hasThumb();
String getUrl(); String getUrl();
void setUrl(String url); void setUrl(String url);

View file

@ -501,4 +501,8 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
return getURI() + " " + getName(); return getURI() + " " + getName();
} }
} }
public boolean hasThumb() {
return getThumbUrl() != null && ! getThumbUrl().isEmpty();
}
} }

View file

@ -646,4 +646,10 @@ public class IndividualFiltering implements Individual {
// Since the statements have been filtered, we can just take the first individual without filtering. // Since the statements have been filtered, we can just take the first individual without filtering.
return stmts.isEmpty() ? null : stmts.get(0).getObject(); return stmts.isEmpty() ? null : stmts.get(0).getObject();
} }
@Override
public boolean hasThumb() {
return _innerIndividual.hasThumb();
}
} }

View file

@ -71,6 +71,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
SDBDatasetMode.ASSERTIONS_AND_INFERENCES; SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
private String individualURI = null; private String individualURI = null;
private Model model = null; private Model model = null;
private Boolean _hasThumb = null;
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
@ -431,39 +432,92 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
public Date getSunrise() { public Date getSunrise() {
if (sunrise != null) { if( this.sunrise == null ){
return sunrise; String[] graphVars = { "?g" };
} else { String getPropertyValue =
constructProperty(ind, VitroVocabulary.SUNRISE); "SELECT ?value" +
ind.getOntModel().enterCriticalSection(Lock.READ); "WHERE { GRAPH ?g { <" + individualURI + "> " +
try { "<" + webappDaoFactory.getJenaBaseDao().SUNRISE + "> " +
sunrise = webappDaoFactory.getJenaBaseDao() "?value} \n" +
.getPropertyDateTimeValue( WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
ind,webappDaoFactory.getJenaBaseDao().SUNRISE); "}";
return sunrise; DatasetWrapper w = getDatasetWrapper();
} finally { Dataset dataset = w.getDataset();
ind.getOntModel().leaveCriticalSection(); 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() { public Date getSunset() {
if (sunset != null) {
return sunset; if( this.sunset == null ){
} else { String[] graphVars = { "?g" };
constructProperty(ind, VitroVocabulary.SUNSET); String getPropertyValue =
ind.getOntModel().enterCriticalSection(Lock.READ); "SELECT ?value" +
try { "WHERE { GRAPH ?g { <" + individualURI + "> " +
sunset = webappDaoFactory.getJenaBaseDao() "<"+webappDaoFactory.getJenaBaseDao().SUNSET+"> " +
.getPropertyDateTimeValue( "?value} \n" +
ind,webappDaoFactory.getJenaBaseDao().SUNSET); WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
return sunset; "}";
} finally { DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
ind.getOntModel().leaveCriticalSection(); 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() { public Date getTimekey() {
@ -691,6 +745,35 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.imageInfo.getThumbnail().getBytestreamAliasUrl(); return this.imageInfo.getThumbnail().getBytestreamAliasUrl();
} }
@Override
public boolean hasThumb(){
if( _hasThumb != null ){
return _hasThumb;
}else{
String[] graphVars = { "?g" };
String ask =
"ASK { GRAPH ?g " +
" { <" + individualURI + "> <http://vitro.mannlib.cornell.edu/ns/vitro/public#mainImage> ?mainImage . \n" +
" ?mainImage <http://vitro.mannlib.cornell.edu/ns/vitro/public#thumbnailImage> ?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() { public String getAnchor() {
if (this.anchor != null) { if (this.anchor != null) {
return anchor; return anchor;

View file

@ -221,7 +221,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{
try{ try{
value = null; value = null;
if( ent.getThumbUrl() != null ) if( ent.hasThumb() )
doc.add(new Field(term.THUMBNAIL, "1", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field(term.THUMBNAIL, "1", Field.Store.YES, Field.Index.NOT_ANALYZED));
else else
doc.add(new Field(term.THUMBNAIL, "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); 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); doPortalFlags(ent, doc);
//do flag 2 legacy, only used at Cornell //do flag 2 legacy, only used at Cornell
doFlag2( ent, doc ); //doFlag2( ent, doc );
//ALLTEXT, all of the 'full text' //ALLTEXT, all of the 'full text'
String t=null; String t=null;