Index: metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventFileLog.java
===================================================================
--- metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventFileLog.java	(revision 7805)
+++ metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventFileLog.java	(revision 7806)
@@ -133,7 +133,7 @@
      * previous timed indexing (including the ones in the timed indexing).
      * @return the list of failure identifiers. The null will be returned if no failure. 
      */
-    public List<Identifier> getFailedPids() throws IndexEventLogException {
+    public List<String> getFailedPids() throws IndexEventLogException {
         return null;
     }
     
Index: metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventLog.java
===================================================================
--- metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventLog.java	(revision 7805)
+++ metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/event/IndexEventLog.java	(revision 7806)
@@ -58,7 +58,7 @@
      * previous timed indexing (including the ones in the timed indexing).
      * @return the list of failure identifiers. The null will be returned if no failure. 
      */
-    public List<Identifier> getFailedPids() throws IndexEventLogException;
+    public List<String> getFailedPids() throws IndexEventLogException;
     
     
     /**
Index: metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
===================================================================
--- metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java	(revision 7805)
+++ metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java	(revision 7806)
@@ -57,6 +57,7 @@
 
 import edu.ucsb.nceas.metacat.index.event.EventlogFactory;
 import edu.ucsb.nceas.metacat.index.event.IndexEvent;
+import edu.ucsb.nceas.metacat.index.event.IndexEventLogException;
 
 
 /**
@@ -119,17 +120,19 @@
      * @throws NotAuthorized 
      * @throws InvalidToken 
      * @throws InvalidRequest 
+     * @throws IndexEventLogException 
+     * @throws IllegalAccessException 
+     * @throws InstantiationException 
+     * @throws ClassNotFoundException 
      */
-    public void indexAll() throws InvalidRequest, InvalidToken, NotAuthorized, 
-                            NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException {
+    /*public void indexAll() throws InvalidRequest, InvalidToken, NotAuthorized, 
+                            NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, IndexEventLogException {
         boolean force = false;
         indexAll(force);
-    }
+    }*/
     
     /**
-     * Build the index for all documents. If force is true, the existed index for documents
-     * will be overwritten. 
-     * @param force
+     * Build the index for all documents.
      * @throws SolrServerException 
      * @throws ServiceFailure 
      * @throws NotImplemented 
@@ -136,18 +139,21 @@
      * @throws NotAuthorized 
      * @throws InvalidToken 
      * @throws InvalidRequest 
+     * @throws IndexEventLogException 
+     * @throws IllegalAccessException 
+     * @throws InstantiationException 
+     * @throws ClassNotFoundException 
      */
-    public void indexAll(boolean force) throws InvalidRequest, InvalidToken,
-                NotAuthorized, NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException {
+    public void indexAll() throws InvalidRequest, InvalidToken,
+                NotAuthorized, NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, IndexEventLogException {
         Date since = null;
         Date until = null;
-        index(since, until, force);
+        index(since, until);
     }
     
     /**
      * Build the index for the docs which have been modified since the specified date.
      * @param since
-     * @param force 
      * @throws SolrServerException 
      * @throws ServiceFailure 
      * @throws NotImplemented 
@@ -154,11 +160,15 @@
      * @throws NotAuthorized 
      * @throws InvalidToken 
      * @throws InvalidRequest 
+     * @throws IndexEventLogException 
+     * @throws IllegalAccessException 
+     * @throws InstantiationException 
+     * @throws ClassNotFoundException 
      */
-    public void index(Date since, boolean force) throws InvalidRequest, InvalidToken, 
-                    NotAuthorized, NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException {
+    public void index(Date since) throws InvalidRequest, InvalidToken, 
+                    NotAuthorized, NotImplemented, ServiceFailure, SolrServerException, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, IndexEventLogException {
         Date until = null;
-        index(since, until, force);
+        index(since, until);
     }
     
     /**
@@ -165,7 +175,6 @@
      *  Build the index for the docs which have been modified between the specified date.s
      * @param since
      * @param until
-     * @param force
      * @throws SolrServerException 
      * @throws ServiceFailure 
      * @throws NotImplemented 
@@ -173,40 +182,95 @@
      * @throws InvalidToken 
      * @throws InvalidRequest 
      * @throws FileNotFoundException 
+     * @throws IndexEventLogException 
+     * @throws IllegalAccessException 
+     * @throws InstantiationException 
+     * @throws ClassNotFoundException 
      */
-    public void index(Date since, Date until, boolean force) throws SolrServerException, InvalidRequest, 
-                                                InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, FileNotFoundException {
+    public void index(Date since, Date until) throws SolrServerException, InvalidRequest, 
+                                                InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, IndexEventLogException {
+        Date processedDate = null;
         List<String> solrIds = null;
         initSystemMetadataMap();
         initObjectPathMap();
-        List[] allMetacatIds = getMetacatIds(since, until);
-        List<String> otherMetacatIds = allMetacatIds[FIRST];
-        List<String> resourceMapIds = allMetacatIds[SECOND];
-        log.info("the metacat ids (exception resource map -----------------------------"+otherMetacatIds);
-        log.info("the metacat resroucemap ids -----------------------------"+resourceMapIds);
-        if(!force) {
-            solrIds = getSolrDocIds();
+        List[] metacatIds = getMetacatIds(since, until);
+        List<String> otherMetacatIds = metacatIds[FIRST];
+        List<String> resourceMapIds =  metacatIds[SECOND];
+        
+        //figure out the procesedDate by comparing the last element of otherMetacatIds and resourceMapIds.
+        Date latestOtherId = null;
+        if (otherMetacatIds != null && !otherMetacatIds.isEmpty()) {
+            int size = otherMetacatIds.size();
+            String id = otherMetacatIds.get(size-1);
+            SystemMetadata sysmeta = getSystemMetadata(id);
+            latestOtherId = sysmeta.getDateSysMetadataModified();
         }
-        log.info("the solr ids -----------------------------"+solrIds);
-        index(otherMetacatIds, solrIds, force);
-        index(resourceMapIds, solrIds, force);
+        Date latestResourceId = null;
+        if (resourceMapIds != null && !resourceMapIds.isEmpty()) {
+            int size = resourceMapIds.size();
+            String id = resourceMapIds.get(size-1);
+            SystemMetadata sysmeta = getSystemMetadata(id);
+            latestResourceId = sysmeta.getDateSysMetadataModified();
+        }
+        if(latestOtherId != null && latestResourceId != null && latestOtherId.getTime() > latestResourceId.getTime()) {
+            processedDate = latestOtherId;
+        } else if (latestOtherId != null && latestResourceId != null && latestOtherId.getTime()  <= latestResourceId.getTime()) {
+            processedDate = latestResourceId;
+        } else if (latestOtherId == null && latestResourceId != null) {
+            processedDate = latestResourceId;
+        } else if (latestOtherId != null && latestResourceId == null) {
+            processedDate = latestOtherId;
+        }
+        
+        //add the failedPids 
+        List<String> failedPids = EventlogFactory.createIndexEventLog().getFailedPids();
+        List<String> failedOtherIds = new ArrayList<String>();
+        List<String> failedResourceMapIds = new ArrayList<String>();
+        if(failedPids != null) {
+            for(String id : failedPids) {
+                SystemMetadata sysmeta = getSystemMetadata(id);
+                if(sysmeta != null && !sysmeta.getArchived()) {
+                    ObjectFormatIdentifier formatId =sysmeta.getFormatId();
+                    if(formatId != null && formatId.getValue() != null && resourceMapNamespaces != null && isResourceMap(formatId)) {
+                        failedResourceMapIds.add(id);
+                    } else {
+                        failedOtherIds.add(id);
+                    }
+                }
+            }
+        }
+        
+        if(!failedOtherIds.isEmpty()) {
+            failedOtherIds.addAll(otherMetacatIds);
+        } else {
+            failedOtherIds = otherMetacatIds;
+        }
+        
+        if(!failedResourceMapIds.isEmpty()) {
+            failedResourceMapIds.addAll(resourceMapIds);
+        } else {
+            failedResourceMapIds = resourceMapIds;
+        }
+        
+        log.info("the metacat ids (exception resource map -----------------------------"+failedOtherIds);
+        log.info("the metacat resroucemap ids -----------------------------"+failedResourceMapIds);
+        index(failedOtherIds);
+        index(failedResourceMapIds);
        
+        //record the timed index.
+        if(processedDate != null) {
+            EventlogFactory.createIndexEventLog().setLastProcessDate(processedDate);
+        }
         
     }
     
     /*
-     * Doing index when it is necessary when compare metacatids and solrids.
+     * Doing index
      */
-    private void index(List<String> metacatIds, List<String>solrIds, boolean force) {
+    private void index(List<String> metacatIds) {
         if(metacatIds != null) {
             for(String metacatId : metacatIds) {
                 if(metacatId != null) {
-                    boolean buildIndex = true;
-                    if(!force && solrIds != null && solrIds.contains(metacatId)) {
-                        //solr already indexs the id and we don't force it to rebuild it, so set the buildIndex to be false
-                        buildIndex = false;
-                    }
-                    if(buildIndex) {
                         try {
                             generateIndex(metacatId);
                         } catch (Exception e) {
@@ -213,7 +277,7 @@
                             log.error("IndexGenerator.index - Metacat Index couldn't generate the index for the id - "+metacatId+" because "+e.getMessage());
                         }
                         
-                    }
+                   
                 }
             }
         }
@@ -230,8 +294,8 @@
             log.error("IndexGenerator.run - IndexEventLog can't log the timed indexing start event :"+e.getMessage());
         }*/
         try {
-            
-            indexAll();
+            Date since = EventlogFactory.createIndexEventLog().getLastProcessDate();
+            index(since);
         } catch (InvalidRequest e) {
             // TODO Auto-generated catch block
             //e.printStackTrace();
@@ -265,7 +329,19 @@
             EventlogFactory.createIndexEventLog().write(event);
         } catch (Exception e) {
             log.error("IndexGenerator.run - IndexEventLog can't log the timed indexing finish event :"+e.getMessage());
-        }*/
+        }*/ catch (ClassNotFoundException e) {
+            // TODO Auto-generated catch block
+            log.error("IndexGenerator.run - Metadata-Index couldn't generate indexes for those documents which haven't been indexed : "+e.getMessage());
+        } catch (InstantiationException e) {
+            // TODO Auto-generated catch block
+            log.error("IndexGenerator.run - Metadata-Index couldn't generate indexes for those documents which haven't been indexed : "+e.getMessage());
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            log.error("IndexGenerator.run - Metadata-Index couldn't generate indexes for those documents which haven't been indexed : "+e.getMessage());
+        } catch (IndexEventLogException e) {
+            // TODO Auto-generated catch block
+            log.error("IndexGenerator.run - Metadata-Index couldn't generate indexes for those documents which haven't been indexed : "+e.getMessage());
+        }
     }
     
     /*
@@ -278,9 +354,12 @@
     }
     
     /*
-     * Get an array of the list of ids of the metacat. If since and util are null, it will return all of them.
+     * Get an array of the list of ids of the metacat which has the systemmetadata modification in the range.
+     * 
+     * If since and util are null, it will return all of them.
      * The first element of the list is the ids except the resource map. The second elements of the list is the ids of the resource map.
-     * The reason to split them is when we index the resource map, we need the index of the document in the resource map ready.
+     * The reason to split them is when we index the resource map, we need the index of the documents in the resource map ready.
+     * The last element in the each list has the latest SystemMetadata modification date. But they are not sorted.
      */
     private List[] getMetacatIds(Date since, Date until) throws InvalidRequest, 
                         InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, FileNotFoundException {
@@ -291,6 +370,8 @@
         ids[FIRST]= otherIds;
         ids[SECOND] = resourceMapIds;
         ISet<Identifier> metacatIds = DistributedMapsFactory.getIdentifiersSet();
+        Date otherPreviousDate = null;
+        Date resourceMapPreviousDate = null;
         if(metacatIds != null) {
             for(Identifier identifier : metacatIds) {
                 if(identifier != null && identifier.getValue() != null && !identifier.getValue().equals("")) {
@@ -317,38 +398,36 @@
                             }
                         }
                         if(correctTimeRange && formatId != null && formatId.getValue() != null && resourceMapNamespaces != null && isResourceMap(formatId)) {
-                            resourceMapIds.add(identifier.getValue());
+                            //for the resource map
+                            if(!resourceMapIds.isEmpty()) {
+                                if(sysDate.getTime() > resourceMapPreviousDate.getTime()) {
+                                    resourceMapIds.add(identifier.getValue());//append to the end of the list if current is later than the previous one
+                                } else {
+                                    int size = resourceMapIds.size();//
+                                    resourceMapIds.add(size -1, identifier.getValue());//keep the previous one at the end of the list.
+                                }
+                            } else {
+                                resourceMapIds.add(identifier.getValue());
+                            }
+                            resourceMapPreviousDate = sysDate;
                         } else {
-                            otherIds.add(identifier.getValue());
-                        }
-                    }
-                }
-            }
-        }
-        /*if(objects != null) {
-            List<ObjectInfo> objectInfoList = objects.getObjectInfoList();
-            if(objectInfoList != null) {
-                for(ObjectInfo info : objectInfoList) {
-                    if(info != null) {
-                        Identifier identifier = info.getIdentifier();
-                        if(identifier != null && identifier.getValue() != null && !identifier.getValue().equals("")) {
-                            SystemMetadata sysmeta = getSystemMetadata(identifier.getValue());
-                            if(sysmeta != null && !sysmeta.getArchived()) {
-                                ObjectFormatIdentifier formatId =sysmeta.getFormatId();
-                                //System.out.println("the object format id is "+formatId.getValue());
-                                //System.out.println("the ============ resourcMapNamespaces"+resourceMapNamespaces);
-                                if(formatId != null && formatId.getValue() != null && resourceMapNamespaces != null && isResourceMap(formatId)) {
-                                    resourceMapIds.add(identifier.getValue());
+                            if(!otherIds.isEmpty()) {
+                                if(sysDate.getTime() > otherPreviousDate.getTime()) {
+                                    otherIds.add(identifier.getValue());
                                 } else {
-                                    otherIds.add(identifier.getValue());
+                                    int size = otherIds.size();
+                                    otherIds.add(size-1, identifier.getValue());
                                 }
+                            } else {
+                                otherIds.add(identifier.getValue());
                             }
-                            //ids.add(identifier.getValue());
+                            otherPreviousDate = sysDate;
                         }
+                        
                     }
                 }
             }
-        }*/
+        }
         return ids;
     }
     
