75
75
* one index database per project.
76
76
*
77
77
* @author Trond Norbye
78
- * @author Lubos Kosco , update for lucene 4.0 .0
78
+ * @author Lubos Kosco , update for lucene 4.2 .0
79
79
*/
80
80
public class IndexDatabase {
81
81
@@ -345,7 +345,7 @@ public void update() throws IOException, HistoryException {
345
345
directories .add (project .getPath ());
346
346
}
347
347
}
348
-
348
+
349
349
for (String dir : directories ) {
350
350
File sourceRoot ;
351
351
if ("" .equals (dir )) {
@@ -367,9 +367,11 @@ public void update() throws IOException, HistoryException {
367
367
368
368
try {
369
369
if (numDocs > 0 ) {
370
- uidIter = terms .iterator (null );
371
- TermsEnum .SeekStatus stat = uidIter .seekCeil (new BytesRef (startuid ), true ); //init uid
372
- if (stat ==TermsEnum .SeekStatus .END || stat ==TermsEnum .SeekStatus .NOT_FOUND ) { uidIter =null ; }
370
+ uidIter = terms .iterator (uidIter );
371
+ TermsEnum .SeekStatus stat = uidIter .seekCeil (new BytesRef (startuid )); //init uid
372
+ if (stat ==TermsEnum .SeekStatus .END ) { uidIter =null ;
373
+ log .log (Level .WARNING , "Couldn't find a start term for {0}, empty u field?" , startuid );
374
+ }
373
375
}
374
376
//TODO below should be optional, since it traverses the tree once more to get total count! :(
375
377
int file_cnt = 0 ;
@@ -385,7 +387,8 @@ public void update() throws IOException, HistoryException {
385
387
386
388
while (uidIter != null && uidIter .term () != null && uidIter .term ().utf8ToString ().startsWith (startuid )) {
387
389
removeFile ();
388
- uidIter .next ();
390
+ BytesRef next = uidIter .next ();
391
+ if (next ==null ) {uidIter =null ;}
389
392
}
390
393
} finally {
391
394
reader .close ();
@@ -802,7 +805,7 @@ private boolean isLocal(String path) {
802
805
*
803
806
*/
804
807
private int indexDown (File dir , String parent , boolean count_only , int cur_count , int est_total ) throws IOException {
805
- int lcur_count = cur_count ;
808
+ int lcur_count = cur_count ;
806
809
if (isInterrupted ()) {
807
810
return lcur_count ;
808
811
}
@@ -842,16 +845,18 @@ public int compare(File p1, File p2) {
842
845
if (uidIter != null ) {
843
846
String uid = Util .path2uid (path , DateTools .timeToString (file .lastModified (), DateTools .Resolution .MILLISECOND )); // construct uid for doc
844
847
BytesRef buid = new BytesRef (uid );
845
- while (uidIter .term () != null
848
+ while (uidIter != null && uidIter .term () != null
846
849
&& uidIter .term ().compareTo (emptyBR ) !=0
847
850
&& uidIter .term ().compareTo (buid ) < 0 ) {
848
851
removeFile ();
849
- uidIter .next ();
852
+ BytesRef next = uidIter .next ();
853
+ if (next ==null ) {uidIter =null ;}
850
854
}
851
855
852
- if (uidIter .term () != null
856
+ if (uidIter != null && uidIter .term () != null
853
857
&& uidIter .term ().bytesEquals (buid )) {
854
- uidIter .next (); // keep matching docs
858
+ BytesRef next = uidIter .next (); // keep matching docs
859
+ if (next ==null ) {uidIter =null ;}
855
860
continue ;
856
861
}
857
862
}
@@ -953,8 +958,8 @@ public static void listAllFiles(List<String> subFiles) throws IOException {
953
958
*/
954
959
public void listFiles () throws IOException {
955
960
IndexReader ireader = null ;
956
- TermsEnum iter ;
957
- Terms terms = null ;
961
+ TermsEnum iter = null ;
962
+ Terms terms = null ;
958
963
959
964
try {
960
965
ireader = DirectoryReader .open (indexDirectory ); // open existing index
@@ -963,10 +968,11 @@ public void listFiles() throws IOException {
963
968
Fields uFields = MultiFields .getFields (ireader );//reader.getTermVectors(0);
964
969
terms = uFields .terms (QueryBuilder .U );
965
970
}
966
- iter = terms .iterator (null ); // init uid iterator
967
- while (iter .term () != null ) {
971
+ iter = terms .iterator (iter ); // init uid iterator
972
+ while (iter != null && iter .term () != null ) {
968
973
log .fine (Util .uid2url (iter .term ().utf8ToString ()));
969
- iter .next ();
974
+ BytesRef next =iter .next ();
975
+ if (next ==null ) {iter =null ;}
970
976
}
971
977
} finally {
972
978
@@ -1014,7 +1020,7 @@ static void listFrequentTokens(List<String> subFiles) throws IOException {
1014
1020
public void listTokens (int freq ) throws IOException {
1015
1021
IndexReader ireader = null ;
1016
1022
TermsEnum iter = null ;
1017
- Terms terms = null ;
1023
+ Terms terms = null ;
1018
1024
1019
1025
try {
1020
1026
ireader = DirectoryReader .open (indexDirectory );
@@ -1023,13 +1029,14 @@ public void listTokens(int freq) throws IOException {
1023
1029
Fields uFields = MultiFields .getFields (ireader );//reader.getTermVectors(0);
1024
1030
terms = uFields .terms (QueryBuilder .DEFS );
1025
1031
}
1026
- iter = terms .iterator (null ); // init uid iterator
1027
- while (iter .term () != null ) {
1032
+ iter = terms .iterator (iter ); // init uid iterator
1033
+ while (iter != null && iter .term () != null ) {
1028
1034
//if (iter.term().field().startsWith("f")) {
1029
1035
if (iter .docFreq () > 16 && iter .term ().utf8ToString ().length () > freq ) {
1030
1036
log .warning (iter .term ().utf8ToString ());
1031
1037
}
1032
- iter .next ();
1038
+ BytesRef next = iter .next ();
1039
+ if (next ==null ) {iter =null ;}
1033
1040
/*} else {
1034
1041
break;
1035
1042
}*/
0 commit comments