Moving the check for prohibited from search to Entity2LuceneDoc for performance reasons.
This commit is contained in:
parent
d6adc88ef8
commit
79ac60c8e8
4 changed files with 29 additions and 46 deletions
|
@ -46,7 +46,6 @@ public class IndexBuilder {
|
||||||
private List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>();
|
private List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>();
|
||||||
private IndexerIface indexer = null;
|
private IndexerIface indexer = null;
|
||||||
private ServletContext context = null;
|
private ServletContext context = null;
|
||||||
private ProhibitedFromSearch classesProhibitedFromSearch = null;
|
|
||||||
|
|
||||||
private long lastRun = 0;
|
private long lastRun = 0;
|
||||||
|
|
||||||
|
@ -126,15 +125,6 @@ public class IndexBuilder {
|
||||||
return isReindexRequested() || ! changedUris.isEmpty() ;
|
return isReindexRequested() || ! changedUris.isEmpty() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProhibitedFromSearch getClassesProhibitedFromSearch() {
|
|
||||||
return classesProhibitedFromSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassesProhibitedFromSearch(
|
|
||||||
ProhibitedFromSearch classesProhibitedFromSearch) {
|
|
||||||
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void killIndexingThread() {
|
public void killIndexingThread() {
|
||||||
this.indexingThread.kill();
|
this.indexingThread.kill();
|
||||||
}
|
}
|
||||||
|
@ -351,32 +341,9 @@ public class IndexBuilder {
|
||||||
*/
|
*/
|
||||||
private void indexItem( Individual ind, boolean newDoc){
|
private void indexItem( Individual ind, boolean newDoc){
|
||||||
try{
|
try{
|
||||||
if( ind == null )
|
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 ){
|
|
||||||
indexer.index(ind, newDoc);
|
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){
|
}catch(Throwable ex){
|
||||||
log.warn("IndexBuilder.indexItem() Error indexing "
|
log.warn("IndexBuilder.indexItem() Error indexing "
|
||||||
+ ind + "\n" +ex);
|
+ ind + "\n" +ex);
|
||||||
|
|
|
@ -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.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
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.search.docbuilder.Obj2DocIface;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||||
|
|
||||||
|
@ -84,6 +85,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{
|
||||||
public static VitroLuceneTermNames term = new VitroLuceneTermNames();
|
public static VitroLuceneTermNames term = new VitroLuceneTermNames();
|
||||||
|
|
||||||
private static String entClassName = Individual.class.getName();
|
private static String entClassName = Individual.class.getName();
|
||||||
|
private ProhibitedFromSearch classesProhibitedFromSearch = null;
|
||||||
|
|
||||||
public boolean canTranslate(Object obj) {
|
public boolean canTranslate(Object obj) {
|
||||||
return (obj != null && obj instanceof Individual);
|
return (obj != null && obj instanceof Individual);
|
||||||
|
@ -105,6 +107,13 @@ public class Entity2LuceneDoc implements Obj2DocIface{
|
||||||
throw new IndexingException("Not indexing bnodes");
|
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,
|
doc.add( new Field(term.DOCID, entClassName + id,
|
||||||
Field.Store.YES, Field.Index.NOT_ANALYZED));
|
Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
|
|
||||||
|
@ -145,7 +154,6 @@ public class Entity2LuceneDoc implements Obj2DocIface{
|
||||||
doc.setBoost(ent.getSearchBoost());
|
doc.setBoost(ent.getSearchBoost());
|
||||||
|
|
||||||
//rdf:type and ClassGroup
|
//rdf:type and ClassGroup
|
||||||
List<VClass> vclasses = ent.getVClasses(false);
|
|
||||||
for( VClass clz : vclasses){
|
for( VClass clz : vclasses){
|
||||||
//document boost for given classes
|
//document boost for given classes
|
||||||
if( clz.getSearchBoost() != null )
|
if( clz.getSearchBoost() != null )
|
||||||
|
@ -380,6 +388,15 @@ public class Entity2LuceneDoc implements Obj2DocIface{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProhibitedFromSearch getClassesProhibitedFromSearch() {
|
||||||
|
return classesProhibitedFromSearch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassesProhibitedFromSearch(
|
||||||
|
ProhibitedFromSearch classesProhibitedFromSearch) {
|
||||||
|
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
|
||||||
|
}
|
||||||
|
|
||||||
public static float NAME_BOOST = 10;
|
public static float NAME_BOOST = 10;
|
||||||
public static float KEYWORD_BOOST = 2;
|
public static float KEYWORD_BOOST = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
log.debug("added " + ind.getName() + " " + ind.getURI());
|
log.debug("added " + ind.getName() + " " + ind.getURI());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
log.debug("could not translate, removing from index " + ind.getURI());
|
log.debug("removing from index " + ind.getURI());
|
||||||
writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// This will attempt to create a new directory and empty index if there is none.
|
||||||
LuceneIndexer indexer = new LuceneIndexer(getBaseIndexDirName(),liveIndexDir, null, getAnalyzer());
|
LuceneIndexer indexer = new LuceneIndexer(getBaseIndexDirName(),liveIndexDir, null, getAnalyzer());
|
||||||
context.setAttribute(ANALYZER, 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);
|
context.setAttribute(LuceneIndexer.class.getName(), indexer);
|
||||||
indexer.setLuceneIndexFactory(lif);
|
indexer.setLuceneIndexFactory(lif);
|
||||||
|
|
||||||
|
@ -136,11 +140,6 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||||
ModelContext.getUnionOntModelSelector(ctx).getABoxModel()
|
ModelContext.getUnionOntModelSelector(ctx).getABoxModel()
|
||||||
.getBaseModel().register(srl);
|
.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 &&
|
if( (Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) instanceof Boolean &&
|
||||||
(Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) ){
|
(Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) ){
|
||||||
log.info("Rebuild of lucene index required before startup.");
|
log.info("Rebuild of lucene index required before startup.");
|
||||||
|
|
Loading…
Add table
Reference in a new issue