MERGED BY HAND r5362 from branch vivonih-rel-1.1-maint
Removing search index rebuild at tomcat startup NIHVIVO-900
This commit is contained in:
parent
60f6f401f3
commit
30890a7b5f
1 changed files with 75 additions and 66 deletions
|
@ -1,7 +1,7 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.lucene;
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.lucene;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.ALLTEXT;
|
||||
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.ALLTEXTUNSTEMMED;
|
||||
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.NAME;
|
||||
|
@ -37,33 +37,33 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
|||
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
|
||||
|
||||
/**
|
||||
* Setup objects for lucene searching and indexing.
|
||||
*
|
||||
* The indexing and search objects, IndexBuilder and Searcher are found by the
|
||||
* controllers IndexController and SearchController through the servletContext.
|
||||
* This object will have the method contextInitialized() called when the tomcat
|
||||
* server starts this webapp.
|
||||
*
|
||||
* The contextInitialized() will try to find the lucene index directory,
|
||||
* make a LueceneIndexer and a LuceneSearcher. The LuceneIndexer will
|
||||
* also get a list of Obj2Doc objects so it can translate object to lucene docs.
|
||||
*
|
||||
* To execute this at context creation put this in web.xml:
|
||||
<listener>
|
||||
<listener-class>
|
||||
edu.cornell.mannlib.vitro.search.setup.LuceneSetup
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||
private static String indexDir = null;
|
||||
private static final Log log = LogFactory.getLog(LuceneSetup.class.getName());
|
||||
|
||||
|
||||
/**
|
||||
* Setup objects for lucene searching and indexing.
|
||||
*
|
||||
* The indexing and search objects, IndexBuilder and Searcher are found by the
|
||||
* controllers IndexController and SearchController through the servletContext.
|
||||
* This object will have the method contextInitialized() called when the tomcat
|
||||
* server starts this webapp.
|
||||
*
|
||||
* The contextInitialized() will try to find the lucene index directory,
|
||||
* make a LueceneIndexer and a LuceneSearcher. The LuceneIndexer will
|
||||
* also get a list of Obj2Doc objects so it can translate object to lucene docs.
|
||||
*
|
||||
* To execute this at context creation put this in web.xml:
|
||||
<listener>
|
||||
<listener-class>
|
||||
edu.cornell.mannlib.vitro.search.setup.LuceneSetup
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||
private static String indexDir = null;
|
||||
private static final Log log = LogFactory.getLog(LuceneSetup.class.getName());
|
||||
|
||||
/**
|
||||
* Gets run to set up DataSource when the webapp servlet context gets
|
||||
* created.
|
||||
|
@ -78,33 +78,33 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
|||
|
||||
setBoolMax();
|
||||
|
||||
// these should really be set as annotation properties.
|
||||
// these should really be set as annotation properties.
|
||||
HashSet<String> dataPropertyBlacklist = new HashSet<String>();
|
||||
context.setAttribute(SEARCH_DATAPROPERTY_BLACKLIST, dataPropertyBlacklist);
|
||||
HashSet<String> objectPropertyBlacklist = new HashSet<String>();
|
||||
objectPropertyBlacklist.add("http://www.w3.org/2002/07/owl#differentFrom");
|
||||
context.setAttribute(SEARCH_OBJECTPROPERTY_BLACKLIST, objectPropertyBlacklist);
|
||||
|
||||
// Here we want to put the LuceneIndex object into the application scope.
|
||||
// This will attempt to create a new directory and empty index if there is none.
|
||||
// Here we want to put the LuceneIndex object into the application scope.
|
||||
// This will attempt to create a new directory and empty index if there is none.
|
||||
LuceneIndexer indexer = new LuceneIndexer(indexDir, null, getAnalyzer());
|
||||
context.setAttribute(ANALYZER, getAnalyzer());
|
||||
context.setAttribute(INDEX_DIR, indexDir);
|
||||
indexer.addObj2Doc(new Entity2LuceneDoc());
|
||||
context.setAttribute(LuceneIndexer.class.getName(), indexer);
|
||||
|
||||
// Here we want to put the LuceneSearcher in the application scope.
|
||||
// the queries need to know the analyzer to use so that the same one can be used
|
||||
// to analyze the fields in the incoming user query terms.
|
||||
// Here we want to put the LuceneSearcher in the application scope.
|
||||
// the queries need to know the analyzer to use so that the same one can be used
|
||||
// to analyze the fields in the incoming user query terms.
|
||||
LuceneSearcher searcher = new LuceneSearcher(
|
||||
new LuceneQueryFactory(getAnalyzer(), ALLTEXT), indexDir);
|
||||
searcher.addObj2Doc(new Entity2LuceneDoc());
|
||||
context.setAttribute(Searcher.class.getName(), searcher);
|
||||
indexer.addSearcher(searcher);
|
||||
|
||||
// This is where the builder gets the list of places to try to
|
||||
// get objects to index. It is filtered so that non-public text
|
||||
// does not get into the search index.
|
||||
// This is where the builder gets the list of places to try to
|
||||
// get objects to index. It is filtered so that non-public text
|
||||
// does not get into the search index.
|
||||
WebappDaoFactory wadf = (WebappDaoFactory) context.getAttribute("webappDaoFactory");
|
||||
VitroFilters vf = VitroFilterUtils.getDisplayFilterByRoleLevel(RoleLevel.PUBLIC, wadf);
|
||||
wadf = new WebappDaoFactoryFiltering(wadf, vf);
|
||||
|
@ -114,8 +114,8 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
|||
|
||||
IndexBuilder builder = new IndexBuilder(context, indexer, sources);
|
||||
|
||||
// here we add the IndexBuilder with the LuceneIndexer
|
||||
// to the servlet context so we can access it later in the webapp.
|
||||
// here we add the IndexBuilder with the LuceneIndexer
|
||||
// to the servlet context so we can access it later in the webapp.
|
||||
context.setAttribute(IndexBuilder.class.getName(), builder);
|
||||
|
||||
// set up listeners so search index builder is notified of changes to model
|
||||
|
@ -131,16 +131,24 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
|||
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
|
||||
builder.setClassesProhibitedFromSearch(
|
||||
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel));
|
||||
|
||||
log.debug("**** End of " + this.getClass().getName() + ".contextInitialized()");
|
||||
|
||||
if( (Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) instanceof Boolean &&
|
||||
(Boolean)sce.getServletContext().getAttribute(INDEX_REBUILD_REQUESTED_AT_STARTUP) ){
|
||||
builder.doIndexRebuild();
|
||||
log.info("Rebuild of search index required before startup.");
|
||||
while( builder.isIndexing() ){
|
||||
Thread.currentThread().sleep(200);
|
||||
log.info("Still rebulding search index");
|
||||
}
|
||||
log.info("Search index rebuild completed.");
|
||||
}
|
||||
|
||||
// Start a rebuild each time the server starts.
|
||||
builder.doIndexRebuild();
|
||||
log.debug("**** End of " + this.getClass().getName() + ".contextInitialized()");
|
||||
} catch (Throwable t) {
|
||||
log.error("***** Error setting up Lucene search *****", t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets run when the webApp Context gets destroyed.
|
||||
*/
|
||||
|
@ -160,7 +168,7 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
|||
public static void setBoolMax() {
|
||||
BooleanQuery.setMaxClauseCount(16384);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the directory to store the lucene index in. The
|
||||
* {@link ConfigurationProperties} should have a property named
|
||||
|
@ -194,28 +202,29 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
|||
}
|
||||
|
||||
return dirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the analyzer that will be used when building the indexing
|
||||
* and when analyzing the incoming search terms.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Analyzer getAnalyzer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the analyzer that will be used when building the indexing
|
||||
* and when analyzing the incoming search terms.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Analyzer getAnalyzer() {
|
||||
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper( new KeywordAnalyzer());
|
||||
analyzer.addAnalyzer(ALLTEXT, new HtmlLowerStopStemAnalyzer());
|
||||
analyzer.addAnalyzer(NAME, new HtmlLowerStopStemAnalyzer());
|
||||
analyzer.addAnalyzer(ALLTEXTUNSTEMMED, new HtmlLowerStopAnalyzer());
|
||||
analyzer.addAnalyzer(NAMEUNSTEMMED, new HtmlLowerStopAnalyzer());
|
||||
return analyzer;
|
||||
return analyzer;
|
||||
}
|
||||
|
||||
public static final String ANALYZER= "lucene.analyzer";
|
||||
public static final String INDEX_DIR = "lucene.indexDir";
|
||||
public static final String SEARCH_DATAPROPERTY_BLACKLIST =
|
||||
"search.dataproperty.blacklist";
|
||||
public static final String SEARCH_OBJECTPROPERTY_BLACKLIST =
|
||||
"search.objectproperty.blacklist";
|
||||
|
||||
}
|
||||
|
||||
public static final String INDEX_REBUILD_REQUESTED_AT_STARTUP = "LuceneSetup.indexRebuildRequestedAtStarup";
|
||||
public static final String ANALYZER= "lucene.analyzer";
|
||||
public static final String INDEX_DIR = "lucene.indexDir";
|
||||
public static final String SEARCH_DATAPROPERTY_BLACKLIST =
|
||||
"search.dataproperty.blacklist";
|
||||
public static final String SEARCH_OBJECTPROPERTY_BLACKLIST =
|
||||
"search.objectproperty.blacklist";
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue