knguyen 2005/06/01 12:45:10 CEST
Modified files: (Branch: JAHIA-4-1-BRANCH)
src/java/org/jahia/services/search JahiaSearchBaseService.java
Log:
- compact index every x interval
Revision Changes Path
1.42.2.15.2.13 +33 -3
jahia/src/java/org/jahia/services/search/JahiaSearchBaseService.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/search/JahiaSearchBaseService.java.diff?r1=1.42.2.15.2.12&r2=1.42.2.15.2.13&f=h
Index: JahiaSearchBaseService.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/search/Attic/JahiaSearchBaseService.java,v
retrieving revision 1.42.2.15.2.12
retrieving revision 1.42.2.15.2.13
diff -u -r1.42.2.15.2.12 -r1.42.2.15.2.13
--- JahiaSearchBaseService.java 27 May 2005 14:38:44 -0000
1.42.2.15.2.12
+++ JahiaSearchBaseService.java 1 Jun 2005 10:45:09 -0000
1.42.2.15.2.13
@@ -96,6 +96,7 @@
private IndexationJobDetail scheduledIndexationJob;
private long scheduledIndexationInterval = 5000;
+ private long optimizationInterval = 300000;
private Thread backgroundIndexingThread;
private boolean indexingThreadActivated = true;
@@ -249,7 +250,7 @@
logger.debug("backgroundIndexingThread name=" +
backgroundIndexingThread.getName());
}
-
+ mIsServiceInitialized = true;
logger.debug("Initialized");
}
}
@@ -269,6 +270,14 @@
}
this.ramIndexer = new RAMIndexer(indexAnalyzer,i);
}
+ try {
+ val = searchSettings.getProperty("optimizationInterval");
+ this.optimizationInterval = Integer.parseInt(val);
+ } catch ( Throwable t ){
+ }
+ if ( this.optimizationInterval < 60000 ){
+ this.optimizationInterval = 300000;
+ }
}
private void startScheduledIndexationJob(){
@@ -931,6 +940,7 @@
writer = getIndexWriter (siteID, this.indexAnalyzer, false);
if (writer == null)
return false;
+ writer.setUseCompoundFile(true);
writer.optimize ();
result = true;
} catch (Throwable t) {
@@ -993,7 +1003,7 @@
SiteIndexer siteIndexer = null;
Integer siteId = null;
HashMap siteIndexers = new HashMap();
-
+ long lastOptimizationTime = System.currentTimeMillis();
while (this.isInitialized() && indexingThreadActivated) {
Vector v = new Vector();
@@ -1109,13 +1119,18 @@
}
}
- long indexingElapsedTime = System.currentTimeMillis() -
indexingStartTime;
+ long indexingElapsedTime = now - indexingStartTime;
if (logger.isInfoEnabled()) {
logger.info(
"Finished processing " + indexOrderCount +
" indexing orders in " + indexingElapsedTime + "ms.");
}
+ if ( ( now - lastOptimizationTime) > this.optimizationInterval )
{
+ optimizeAllIndexes();
+ lastOptimizationTime = now;
+ }
+
// FIXME : oops, As we are in a separate thread, this would may
have sence
// to terminate Connection ?
org.jahia.services.database.ConnectionDispenser.
@@ -1126,6 +1141,8 @@
size = indexOrders.size();
}
if (size == 0) {
+ lastOptimizationTime = now;
+ optimizeAllIndexes();
synchronized (lock) {
try {
lock.wait(); // wait for next notify
@@ -1143,6 +1160,19 @@
//
//**************************************************************************
+ private void optimizeAllIndexes() {
+ try {
+ Enumeration sites =
ServicesRegistry.getInstance().getJahiaSitesService().getSites();
+ JahiaSite site = null;
+ while ( sites.hasMoreElements() ){
+ site = (JahiaSite)sites.nextElement();
+ this.optimizeIndex(site.getID());
+ }
+ } catch ( Throwable t) {
+ logger.debug("Exception occured when trying to optimize all
indexes ",t);
+ }
+ }
+
//--------------------------------------------------------------------------
/**
* index a JahiaIndexable object