Moving the check for prohibited from search to Entity2LuceneDoc for performance reasons.

This commit is contained in:
bdc34 2011-02-04 22:46:08 +00:00
parent d6adc88ef8
commit 79ac60c8e8
4 changed files with 29 additions and 46 deletions

View file

@ -45,8 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
public class IndexBuilder {
private List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>();
private IndexerIface indexer = null;
private ServletContext context = null;
private ProhibitedFromSearch classesProhibitedFromSearch = null;
private ServletContext context = null;
private long lastRun = 0;
@ -126,15 +125,6 @@ public class IndexBuilder {
return isReindexRequested() || ! changedUris.isEmpty() ;
}
public ProhibitedFromSearch getClassesProhibitedFromSearch() {
return classesProhibitedFromSearch;
}
public void setClassesProhibitedFromSearch(
ProhibitedFromSearch classesProhibitedFromSearch) {
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
}
public void killIndexingThread() {
this.indexingThread.kill();
}
@ -351,32 +341,9 @@ public class IndexBuilder {
*/
private void indexItem( Individual ind, boolean newDoc){
try{
if( ind == null )
return;
if( ind.getVClasses() == null || ind.getVClasses().size() < 1 )
return;
boolean prohibitedClass = false;
VClass prohClass = null;
if( classesProhibitedFromSearch != null ){
for( VClass vclass : ind.getVClasses() ){
if( classesProhibitedFromSearch.isClassProhibited(vclass.getURI()) ){
prohibitedClass = true;
prohClass = vclass;
break;
}
}
}
if( !prohibitedClass ){
if( ind != null ){
indexer.index(ind, newDoc);
}else{
if( ! newDoc ){
//log.debug("removing " + ind.getURI() + " from index because class " + prohClass.getURI() + " is on prohibited list.");
indexer.removeFromIndex(ind);
}else{
//log.debug("not adding " + ind.getURI() + " to index because class " + prohClass.getURI() + " is on prohibited list.");
}
}
}
}catch(Throwable ex){
log.warn("IndexBuilder.indexItem() Error indexing "
+ ind + "\n" +ex);

View file

@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
@ -84,7 +85,8 @@ public class Entity2LuceneDoc implements Obj2DocIface{
public static VitroLuceneTermNames term = new VitroLuceneTermNames();
private static String entClassName = Individual.class.getName();
private ProhibitedFromSearch classesProhibitedFromSearch = null;
public boolean canTranslate(Object obj) {
return (obj != null && obj instanceof Individual);
}
@ -105,6 +107,13 @@ public class Entity2LuceneDoc implements Obj2DocIface{
throw new IndexingException("Not indexing bnodes");
}
List<VClass> vclasses = ent.getVClasses(false);
for( VClass vclass : vclasses ){
if( classesProhibitedFromSearch.isClassProhibited(vclass.getURI()) ){
return null;
}
}
doc.add( new Field(term.DOCID, entClassName + id,
Field.Store.YES, Field.Index.NOT_ANALYZED));
@ -144,8 +153,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{
if( ent.getSearchBoost() != null && ent.getSearchBoost() != 0 )
doc.setBoost(ent.getSearchBoost());
//rdf:type and ClassGroup
List<VClass> vclasses = ent.getVClasses(false);
//rdf:type and ClassGroup
for( VClass clz : vclasses){
//document boost for given classes
if( clz.getSearchBoost() != null )
@ -380,6 +388,15 @@ public class Entity2LuceneDoc implements Obj2DocIface{
return "";
}
public ProhibitedFromSearch getClassesProhibitedFromSearch() {
return classesProhibitedFromSearch;
}
public void setClassesProhibitedFromSearch(
ProhibitedFromSearch classesProhibitedFromSearch) {
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
}
public static float NAME_BOOST = 10;
public static float KEYWORD_BOOST = 2;
}

View file

@ -220,7 +220,7 @@ public class LuceneIndexer implements IndexerIface {
log.debug("added " + ind.getName() + " " + ind.getURI());
}
}else{
log.debug("could not translate, removing from index " + ind.getURI());
log.debug("removing from index " + ind.getURI());
writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
}
}

View file

@ -99,7 +99,11 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
// This will attempt to create a new directory and empty index if there is none.
LuceneIndexer indexer = new LuceneIndexer(getBaseIndexDirName(),liveIndexDir, null, getAnalyzer());
context.setAttribute(ANALYZER, getAnalyzer());
indexer.addObj2Doc(new Entity2LuceneDoc());
Entity2LuceneDoc translator = new Entity2LuceneDoc();
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
translator.setClassesProhibitedFromSearch(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel));
indexer.addObj2Doc(translator);
context.setAttribute(LuceneIndexer.class.getName(), indexer);
indexer.setLuceneIndexFactory(lif);
@ -135,11 +139,6 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
ModelContext.getInferenceOntModel(ctx).register(srl);
ModelContext.getUnionOntModelSelector(ctx).getABoxModel()
.getBaseModel().register(srl);
// set the classes that the indexBuilder ignores
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
builder.setClassesProhibitedFromSearch(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel));
if( (Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) instanceof Boolean &&
(Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) ){