diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexFactory.java index b092f8222..e5a2314e9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexFactory.java @@ -36,7 +36,7 @@ public class LuceneIndexFactory { return getLuceneIndexFactoryFromContext(context).innerGetIndexSearcher(context); } - public static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){ + protected static LuceneIndexFactory getLuceneIndexFactoryFromContext(ServletContext context){ Object obj = context.getAttribute(LUCENE_INDEX_FACTORY); if( obj == null ){ log.error("cannot get LuceneIndexFactory from context. Search is not setup correctly"); @@ -68,6 +68,20 @@ public class LuceneIndexFactory { */ public synchronized void forceNewIndexSearcher(){ log.debug("forcing the re-opening of the search index"); + IndexSearcher oldSearcher = searcher; + + + searcher = null; + } + + protected synchronized void forceClose(){ + log.debug("forcing the closing of the search index"); + try { + if( searcher != null ) + searcher.close(); + } catch (IOException e) { + log.error("could not close lucene searcher: " + e.getMessage()); + } searcher = null; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexer.java index c3d08f46e..cea86aab4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneIndexer.java @@ -280,13 +280,25 @@ public class LuceneIndexer implements IndexerIface { File offLineDir = new File(currentOffLineDir); File liveDir = new File(liveIndexDir); + log.debug("deleting old live directory " + liveDir.getAbsolutePath()); boolean deleted = deleteDir(liveDir); if (! deleted ){ - log.error("failed to delete live index directory " + log.debug("failed to delete live index directory " + liveDir.getAbsolutePath()); + log.debug("Attempting to close searcher and delete live directory"); + this.luceneIndexFactory.forceClose(); + boolean secondDeleted = deleteDir(liveDir); + if( ! secondDeleted ){ + log.error("Search index is out of date and cannot be replaced " + + "because could not remove lucene index from directory" + + liveDir.getAbsolutePath()); + } return; } + log.debug("moving " + offLineDir.getAbsolutePath() + " to " + + liveDir.getAbsolutePath()); + boolean success = offLineDir.renameTo( liveDir ); if( ! success ){ log.error("could not move off line index at " @@ -295,7 +307,11 @@ public class LuceneIndexer implements IndexerIface { return; } - deleteDir(new File(currentOffLineDir)); + File oldWorkignDir = new File(currentOffLineDir); + if( oldWorkignDir.exists() ) + log.debug("old working directory should have been removed " + + "but still exits at " + oldWorkignDir.getAbsolutePath()); + currentOffLineDir = null; } diff --git a/webapp/web/admin/log4j.jsp b/webapp/web/admin/log4j.jsp index c4de3bfce..97c750bb2 100644 --- a/webapp/web/admin/log4j.jsp +++ b/webapp/web/admin/log4j.jsp @@ -103,32 +103,7 @@ try { } out.write("\r\n"); out.write(""); - out.write("\n"); - - - /* write out form to do a test message */ - out.write("

Test the logging configuration by sending a test message

\n"); - out.write("
\n"); - out.write("\n"); - out.write("\n\r"); - out.write(" \n\r"); - out.write(" \n\r"); - - out.write(" \n\r"); - out.write(" \n\r"); - - out.write(" \n\r"); - out.write(" \n\r"); - out.write(" \n\r"); - out.write("
logger:
level:
message:
\n"); + out.write("\n"); out.write("\r\n"); out.flush();