@@ -429,6 +429,10 @@ public void update() throws IOException, HistoryException {
429
429
indexDown (sourceRoot , dir , false , 0 ,
430
430
getFileCount (sourceRoot , dir ));
431
431
432
+ // Remove data for the trailing terms that indexDown()
433
+ // did not traverse. These correspond to files that have
434
+ // been removed and have higher ordering that any terms
435
+ // in the index.
432
436
while (uidIter != null && uidIter .term () != null
433
437
&& uidIter .term ().utf8ToString ().startsWith (startuid )) {
434
438
@@ -910,18 +914,29 @@ private int indexDown(File dir, String parent, boolean count_only,
910
914
DateTools .timeToString (file .lastModified (),
911
915
DateTools .Resolution .MILLISECOND )); // construct uid for doc
912
916
BytesRef buid = new BytesRef (uid );
917
+ // Traverse terms that have smaller UID than the current
918
+ // file, i.e. given the ordering they positioned before the file
919
+ // or it is the file that has been modified.
913
920
while (uidIter != null && uidIter .term () != null
914
921
&& uidIter .term ().compareTo (emptyBR ) != 0
915
922
&& uidIter .term ().compareTo (buid ) < 0 ) {
916
923
924
+ // If the term's path matches path of currently processed file,
925
+ // it is clear that the file has been modified and thus
926
+ // removeFile() will be followed by call to addFile() below.
927
+ // In such case, instruct removeFile() not to remove history
928
+ // cache for the file so that incremental history cache
929
+ // generation works.
917
930
String termPath = Util .uid2url (uidIter .term ().utf8ToString ());
918
931
removeFile (!termPath .equals (path ));
932
+
919
933
BytesRef next = uidIter .next ();
920
934
if (next == null ) {
921
935
uidIter = null ;
922
936
}
923
937
}
924
938
939
+ // If the file was not modified, skip to the next one.
925
940
if (uidIter != null && uidIter .term () != null
926
941
&& uidIter .term ().bytesEquals (buid )) {
927
942
BytesRef next = uidIter .next (); // keep matching docs
0 commit comments