* \r
* @param repositoryName\r
*/\r
- public void close(String repositoryName) {\r
- try {\r
- IndexWriter writer = writers.remove(repositoryName);\r
- if (writer != null) {\r
- writer.close();\r
- }\r
- } catch (Exception e) {\r
- logger.error("Failed to close index writer for " + repositoryName, e);\r
- }\r
-\r
+ public synchronized void close(String repositoryName) {\r
try {\r
IndexSearcher searcher = searchers.remove(repositoryName);\r
if (searcher != null) {\r
- searcher.close();\r
+ searcher.getIndexReader().close();\r
}\r
} catch (Exception e) {\r
logger.error("Failed to close index searcher for " + repositoryName, e);\r
}\r
+ \r
+ try {\r
+ IndexWriter writer = writers.remove(repositoryName);\r
+ if (writer != null) {\r
+ writer.close();\r
+ }\r
+ } catch (Exception e) {\r
+ logger.error("Failed to close index writer for " + repositoryName, e);\r
+ } \r
}\r
\r
/**\r
* Close all Lucene indexers.\r
* \r
*/\r
- public void close() {\r
+ public synchronized void close() {\r
// close all writers\r
for (String writer : writers.keySet()) {\r
try {\r
// close all searchers\r
for (String searcher : searchers.keySet()) {\r
try {\r
- searchers.get(searcher).close();\r
+ searchers.get(searcher).getIndexReader().close();\r
} catch (Throwable t) {\r
logger.error("Failed to close Lucene searcher for " + searcher, t);\r
}\r
*/\r
public boolean deleteIndex(String repositoryName) {\r
try {\r
- // remove the repository index writer from the cache and close it\r
- IndexWriter writer = writers.remove(repositoryName);\r
- if (writer != null) {\r
- writer.close();\r
- writer = null;\r
- }\r
- // remove the repository index searcher from the cache and close it\r
- IndexSearcher searcher = searchers.remove(repositoryName);\r
- if (searcher != null) {\r
- searcher.close();\r
- searcher = null;\r
- }\r
+ // close any open writer/searcher\r
+ close(repositoryName);\r
+\r
// delete the index folder\r
File repositoryFolder = new File(repositoriesFolder, repositoryName);\r
File luceneIndex = new File(repositoryFolder, LUCENE_DIR);\r
* @return IndexResult\r
*/\r
public IndexResult reindex(RepositoryModel model, Repository repository) {\r
- IndexResult result = new IndexResult();\r
+ IndexResult result = new IndexResult(); \r
if (!deleteIndex(model.name)) {\r
return result;\r
}\r
// commit all changes and reset the searcher\r
config.setInt(CONF_INDEX, null, CONF_VERSION, INDEX_VERSION);\r
config.save();\r
- resetIndexSearcher(model.name);\r
writer.commit();\r
+ resetIndexSearcher(model.name);\r
result.success();\r
} catch (Exception e) {\r
logger.error("Exception while reindexing " + model.name, e);\r
try { \r
IndexWriter writer = getIndexWriter(repositoryName);\r
writer.addDocument(doc);\r
- resetIndexSearcher(repositoryName);\r
writer.commit();\r
+ resetIndexSearcher(repositoryName);\r
return true;\r
} catch (Exception e) {\r
logger.error(MessageFormat.format("Exception while incrementally updating {0} Lucene index", repositoryName), e);\r
private synchronized void resetIndexSearcher(String repository) throws IOException {\r
IndexSearcher searcher = searchers.remove(repository);\r
if (searcher != null) {\r
- searcher.close();\r
+ searcher.getIndexReader().close();\r
}\r
}\r
\r