Removed refrences to deprecated lucene APIs.
authorTomas Zezula <tzezula@netbeans.org>
Sun, 23 Jan 2011 09:44:15 +0100
changeset 17294b6a5d77317fa
parent 17293 598fb94dcdda
child 17295 3c793a3084b3
Removed refrences to deprecated lucene APIs.
gsf.tools/src/org/netbeans/modules/gsf/browser/DumpIndex.java
gsf.tools/src/org/netbeans/modules/gsf/tools/lucene/IndexBrowserTopComponent.java
gsf/src/org/netbeans/modules/gsfret/source/usages/DocumentUtil.java
gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndex.java
gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndexMBean.java
gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndexMBeanImpl.java
     1.1 --- a/gsf.tools/src/org/netbeans/modules/gsf/browser/DumpIndex.java	Tue Jan 18 10:17:10 2011 -0500
     1.2 +++ b/gsf.tools/src/org/netbeans/modules/gsf/browser/DumpIndex.java	Sun Jan 23 09:44:15 2011 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  import javax.swing.JFileChooser;
     1.5  import org.apache.lucene.document.Document;
     1.6  import org.apache.lucene.document.Field;
     1.7 +import org.apache.lucene.document.Fieldable;
     1.8  import org.apache.lucene.index.IndexReader;
     1.9  import org.netbeans.modules.gsf.Language;
    1.10  import org.netbeans.modules.gsf.LanguageRegistry;
    1.11 @@ -174,11 +175,7 @@
    1.12                  List<Match> data;
    1.13                  data = new ArrayList<Match>();
    1.14  
    1.15 -                @SuppressWarnings("unchecked")
    1.16 -                Enumeration<Field> en = luceneDoc.fields();
    1.17 -
    1.18 -                while (en.hasMoreElements()) {
    1.19 -                    Field f = en.nextElement();
    1.20 +                for (Fieldable f : (List<Fieldable>)luceneDoc.getFields()) {    //Remove cast in Lucene 3.0
    1.21                      String key = f.name();
    1.22                      // Skip timestamps?
    1.23                      //if (key.equals("timestamp")) {
     2.1 --- a/gsf.tools/src/org/netbeans/modules/gsf/tools/lucene/IndexBrowserTopComponent.java	Tue Jan 18 10:17:10 2011 -0500
     2.2 +++ b/gsf.tools/src/org/netbeans/modules/gsf/tools/lucene/IndexBrowserTopComponent.java	Sun Jan 23 09:44:15 2011 +0100
     2.3 @@ -9,7 +9,6 @@
     2.4  import java.util.Collections;
     2.5  import java.util.Comparator;
     2.6  import java.util.EnumSet;
     2.7 -import java.util.Enumeration;
     2.8  import java.util.HashMap;
     2.9  import java.util.HashSet;
    2.10  import java.util.List;
    2.11 @@ -25,7 +24,7 @@
    2.12  import javax.swing.event.TableModelListener;
    2.13  import javax.swing.table.TableModel;
    2.14  import org.apache.lucene.document.Document;
    2.15 -import org.apache.lucene.document.Field;
    2.16 +import org.apache.lucene.document.Fieldable;
    2.17  import org.apache.lucene.index.IndexReader;
    2.18  import org.netbeans.modules.gsf.api.NameKind;
    2.19  import org.netbeans.modules.gsf.api.Index.SearchResult;
    2.20 @@ -958,10 +957,7 @@
    2.21          }
    2.22          
    2.23          private void initFromLuceneDoc(Document luceneDoc) {
    2.24 -            @SuppressWarnings("unchecked")
    2.25 -            Enumeration<Field> en = luceneDoc.fields();
    2.26 -            while (en.hasMoreElements()) {
    2.27 -                Field f = en.nextElement();
    2.28 +            for (Fieldable f : (List<Fieldable>)luceneDoc.getFields()) {        //Remove cast in Lucene 3.x
    2.29                  String key = f.name();
    2.30                  String value = f.stringValue();
    2.31                  data.add(new Match(key, value));
     3.1 --- a/gsf/src/org/netbeans/modules/gsfret/source/usages/DocumentUtil.java	Tue Jan 18 10:17:10 2011 -0500
     3.2 +++ b/gsf/src/org/netbeans/modules/gsfret/source/usages/DocumentUtil.java	Sun Jan 23 09:44:15 2011 +0100
     3.3 @@ -285,18 +285,18 @@
     3.4          }
     3.5          caseInsensitiveName = simpleName.toLowerCase();         //XXX: I18N, Locale
     3.6          Document doc = new Document ();        
     3.7 -        Field field = new Field (FIELD_BINARY_NAME,fileName,Field.Store.YES, Field.Index.UN_TOKENIZED);
     3.8 +        Field field = new Field (FIELD_BINARY_NAME,fileName,Field.Store.YES, Field.Index.NOT_ANALYZED);
     3.9          doc.add (field);
    3.10 -        field = new Field (FIELD_PACKAGE_NAME,pkgName,Field.Store.YES, Field.Index.UN_TOKENIZED);
    3.11 +        field = new Field (FIELD_PACKAGE_NAME,pkgName,Field.Store.YES, Field.Index.NOT_ANALYZED);
    3.12          doc.add (field);
    3.13          field = new Field (FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO);
    3.14          doc.add (field);
    3.15 -        field = new Field (FIELD_SIMPLE_NAME,simpleName, Field.Store.YES, Field.Index.UN_TOKENIZED);
    3.16 +        field = new Field (FIELD_SIMPLE_NAME,simpleName, Field.Store.YES, Field.Index.NOT_ANALYZED);
    3.17          doc.add (field);
    3.18 -        field = new Field (FIELD_CASE_INSENSITIVE_NAME, caseInsensitiveName, Field.Store.YES, Field.Index.UN_TOKENIZED);
    3.19 +        field = new Field (FIELD_CASE_INSENSITIVE_NAME, caseInsensitiveName, Field.Store.YES, Field.Index.NOT_ANALYZED);
    3.20          doc.add (field);
    3.21          for (String reference : references) {
    3.22 -            field = new Field (FIELD_REFERENCES,reference,Field.Store.YES,Field.Index.UN_TOKENIZED);
    3.23 +            field = new Field (FIELD_REFERENCES,reference,Field.Store.YES,Field.Index.NOT_ANALYZED);
    3.24              doc.add(field);
    3.25          }
    3.26          return doc;
    3.27 @@ -304,7 +304,7 @@
    3.28      
    3.29      public static Document createRootTimeStampDocument (final long timeStamp) {
    3.30          Document doc = new Document ();
    3.31 -        Field field = new Field (FIELD_RESOURCE_NAME, ROOT_NAME,Field.Store.YES, Field.Index.UN_TOKENIZED);
    3.32 +        Field field = new Field (FIELD_RESOURCE_NAME, ROOT_NAME,Field.Store.YES, Field.Index.NOT_ANALYZED);
    3.33          doc.add (field);        
    3.34          field = new Field (FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO);
    3.35          doc.add (field);
     4.1 --- a/gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndex.java	Tue Jan 18 10:17:10 2011 -0500
     4.2 +++ b/gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndex.java	Sun Jan 23 09:44:15 2011 +0100
     4.3 @@ -48,6 +48,7 @@
     4.4  import java.io.IOException;
     4.5  import java.text.ParseException;
     4.6  import java.util.ArrayList;
     4.7 +import java.util.BitSet;
     4.8  import java.util.Collections;
     4.9  import java.util.Comparator;
    4.10  import java.util.Enumeration;
    4.11 @@ -63,12 +64,15 @@
    4.12  import java.util.regex.Matcher;
    4.13  import java.util.regex.Pattern;
    4.14  import org.apache.lucene.document.FieldSelectorResult;
    4.15 +import org.apache.lucene.search.Collector;
    4.16 +import org.apache.lucene.search.Scorer;
    4.17  import org.apache.lucene.store.NoLockFactory;
    4.18  import org.apache.lucene.analysis.KeywordAnalyzer;
    4.19  import org.apache.lucene.document.DateTools;
    4.20  import org.apache.lucene.document.Document;
    4.21  import org.apache.lucene.document.Field;
    4.22  import org.apache.lucene.document.FieldSelector;
    4.23 +import org.apache.lucene.document.Fieldable;
    4.24  import org.apache.lucene.index.IndexReader;
    4.25  import org.apache.lucene.index.IndexWriter;
    4.26  import org.apache.lucene.index.Term;
    4.27 @@ -76,11 +80,11 @@
    4.28  import org.apache.lucene.index.TermEnum;
    4.29  import org.apache.lucene.search.BooleanClause;
    4.30  import org.apache.lucene.search.BooleanQuery;
    4.31 -import org.apache.lucene.search.Hit;
    4.32 -import org.apache.lucene.search.Hits;
    4.33  import org.apache.lucene.search.IndexSearcher;
    4.34 +import org.apache.lucene.search.ScoreDoc;
    4.35  import org.apache.lucene.search.Searcher;
    4.36  import org.apache.lucene.search.TermQuery;
    4.37 +import org.apache.lucene.search.TopDocs;
    4.38  import org.apache.lucene.store.Directory;
    4.39  import org.apache.lucene.store.FSDirectory;
    4.40  import org.apache.lucene.store.RAMDirectory;
    4.41 @@ -149,7 +153,7 @@
    4.42          super(language);
    4.43          assert refCacheRoot != null;
    4.44          this.refCacheRoot = refCacheRoot;
    4.45 -        this.directory = FSDirectory.getDirectory(refCacheRoot, NoLockFactory.getNoLockFactory());      //Locking controlled by rwlock
    4.46 +        this.directory = FSDirectory.open(refCacheRoot, NoLockFactory.getNoLockFactory());      //Locking controlled by rwlock
    4.47      }
    4.48  
    4.49      private void regExpSearch (final Pattern pattern, Term startTerm, final IndexReader in, final Set<Term> toSearch/*, final AtomicBoolean cancel*/, boolean caseSensitive) throws IOException/*, InterruptedException*/ {        
    4.50 @@ -224,28 +228,29 @@
    4.51              return false;
    4.52          }
    4.53          try {
    4.54 -            Searcher searcher = new IndexSearcher (this.getReader());
    4.55 +            final IndexReader in = this.getReader();
    4.56 +            final Searcher searcher = new IndexSearcher (in);
    4.57              try {
    4.58 -                Hits hits;
    4.59 +                TopDocs topDocs;
    4.60                  if (resourceName == null) {
    4.61                      synchronized (this) {
    4.62                          if (this.rootTimeStamp != null) {
    4.63                              return rootTimeStamp.longValue() >= timeStamp;
    4.64                          }
    4.65                      }
    4.66 -                    hits = searcher.search(new TermQuery(DocumentUtil.rootDocumentTerm()));
    4.67 +                    topDocs = searcher.search(new TermQuery(DocumentUtil.rootDocumentTerm()), 2);
    4.68                  }
    4.69                  else {
    4.70 -                    hits = searcher.search(DocumentUtil.binaryNameQuery(resourceName));
    4.71 +                    topDocs = searcher.search(DocumentUtil.binaryNameQuery(resourceName), 2);
    4.72                  }
    4.73  
    4.74 -                if (hits.length() != 1) {   //0 = not present, 1 = present and has timestamp, >1 means broken index, probably killed IDE, treat it as not up to date and store will fix it.
    4.75 +                if (topDocs.totalHits != 1) {   //0 = not present, 1 = present and has timestamp, >1 means broken index, probably killed IDE, treat it as not up to date and store will fix it.
    4.76                      return false;
    4.77                  }
    4.78                  else {
    4.79                      try {
    4.80 -                        Hit hit = (Hit) hits.iterator().next();
    4.81 -                        long cacheTime = DocumentUtil.getTimeStamp(hit.getDocument());
    4.82 +                        ScoreDoc hit = topDocs.scoreDocs[0];
    4.83 +                        long cacheTime = DocumentUtil.getTimeStamp(in.document(hit.doc));
    4.84                          if (resourceName == null) {
    4.85                              synchronized (this) {
    4.86                                  this.rootTimeStamp = new Long (cacheTime);
    4.87 @@ -340,7 +345,7 @@
    4.88          checkPreconditions();
    4.89          this.close ();
    4.90          try {
    4.91 -            final String[] content = this.directory.list();
    4.92 +            final String[] content = this.directory.listAll();
    4.93              boolean dirty = false;
    4.94              for (String file : content) {
    4.95                  try {
    4.96 @@ -381,7 +386,7 @@
    4.97              }
    4.98          } finally {
    4.99              //Need to recreate directory, see issue: #148374
   4.100 -            this.directory = FSDirectory.getDirectory(refCacheRoot, NoLockFactory.getNoLockFactory());      //Locking controlled by rwlock
   4.101 +            this.directory = FSDirectory.open(refCacheRoot, NoLockFactory.getNoLockFactory());      //Locking controlled by rwlock
   4.102              closed = false;
   4.103          }
   4.104      }
   4.105 @@ -424,7 +429,7 @@
   4.106          }
   4.107          //Issue #149757 - logging
   4.108          try {
   4.109 -            IndexWriter writer = new IndexWriter (this.directory,new KeywordAnalyzer(), create);
   4.110 +            IndexWriter writer = new IndexWriter (this.directory,new KeywordAnalyzer(), create, IndexWriter.MaxFieldLength.LIMITED);
   4.111              return writer;
   4.112          } catch (IOException ioe) {
   4.113              throw annotateException (ioe);
   4.114 @@ -500,9 +505,11 @@
   4.115                          BooleanQuery query = new BooleanQuery ();
   4.116                          query.add (new TermQuery (new Term (DocumentUtil.FIELD_FILENAME, fileUrl)),BooleanClause.Occur.MUST);
   4.117  
   4.118 -                        Hits hits = searcher.search(query);
   4.119 -                        for (int i=0; i<hits.length(); i++) {
   4.120 -                            in.deleteDocument (hits.id(i));
   4.121 +                        final BitSet bs  = new BitSet();
   4.122 +                        final BitSetCollector bsCollector = new BitSetCollector(bs);
   4.123 +                        searcher.search(query,bsCollector);
   4.124 +                        for (int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) {
   4.125 +                            in.deleteDocument (i);
   4.126                          }
   4.127                      }
   4.128                      in.deleteDocuments (DocumentUtil.rootDocumentTerm());
   4.129 @@ -517,13 +524,7 @@
   4.130          try {
   4.131              if (debugIndexMerging) {
   4.132                  out.setInfoStream (System.err);
   4.133 -            }
   4.134 -            final LuceneIndexMBean indexSettings = LuceneIndexMBeanImpl.getDefault();
   4.135 -            if (indexSettings != null) {
   4.136 -                out.setMergeFactor(indexSettings.getMergeFactor());
   4.137 -                out.setMaxMergeDocs(indexSettings.getMaxMergeDocs());
   4.138 -                out.setMaxBufferedDocs(indexSettings.getMaxBufferedDocs());
   4.139 -            }        
   4.140 +            }            
   4.141              LowMemoryNotifier lm = LowMemoryNotifier.getDefault();
   4.142              LMListener lmListener = new LMListener ();
   4.143              lm.addLowMemoryListener (lmListener);        
   4.144 @@ -534,7 +535,7 @@
   4.145              }
   4.146              else {
   4.147                  memDir = new RAMDirectory ();
   4.148 -                activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true);
   4.149 +                activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
   4.150              }        
   4.151              try {
   4.152                  activeOut.addDocument (DocumentUtil.createRootTimeStampDocument (timeStamp));
   4.153 @@ -547,17 +548,17 @@
   4.154                              Document newDoc = new Document();
   4.155                              newDoc.add(new Field (DocumentUtil.FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO));
   4.156                              if (document.overrideUrl != null) {
   4.157 -                                newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, document.overrideUrl, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.158 +                                newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, document.overrideUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.159                                  createEmptyUrl = filename;
   4.160                              } else if (filename != null) {
   4.161 -                                newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.162 +                                newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.163                              }
   4.164  
   4.165                              for (int i = 0, n = document.indexedKeys.size(); i < n; i++) {
   4.166                                  String key = document.indexedKeys.get(i);
   4.167                                  String value = document.indexedValues.get(i);
   4.168                                  assert key != null && value != null : "key=" + key + ", value=" + value;
   4.169 -                                Field field = new Field(key, value, Field.Store.YES, Field.Index.UN_TOKENIZED);
   4.170 +                                Field field = new Field(key, value, Field.Store.YES, Field.Index.NOT_ANALYZED);
   4.171                                  newDoc.add(field);
   4.172                              }
   4.173  
   4.174 @@ -577,26 +578,26 @@
   4.175  
   4.176                              Document newDoc = new Document();
   4.177                              newDoc.add(new Field (DocumentUtil.FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO));
   4.178 -                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, createEmptyUrl, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.179 +                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, createEmptyUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.180                              activeOut.addDocument(newDoc);
   4.181                          }
   4.182                      } else if (filename != null && documents != null) { // documents == null: delete
   4.183                          Document newDoc = new Document();
   4.184                          newDoc.add(new Field (DocumentUtil.FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO));
   4.185 -                        newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.186 +                        newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.187                          activeOut.addDocument(newDoc);
   4.188                      }
   4.189                  }
   4.190  
   4.191                  if (memDir != null && lmListener.lowMemory.getAndSet(false)) {                       
   4.192                      activeOut.close();
   4.193 -                    out.addIndexes(new Directory[] {memDir});                        
   4.194 +                    out.addIndexesNoOptimize(new Directory[] {memDir});                        
   4.195                      memDir = new RAMDirectory ();        
   4.196 -                    activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true);
   4.197 +                    activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
   4.198                  }
   4.199                  if (memDir != null) {
   4.200                      activeOut.close();
   4.201 -                    out.addIndexes(new Directory[] {memDir});   
   4.202 +                    out.addIndexesNoOptimize(new Directory[] {memDir});   
   4.203                      activeOut = null;
   4.204                      memDir = null;
   4.205                  }
   4.206 @@ -625,9 +626,11 @@
   4.207                      BooleanQuery query = new BooleanQuery ();
   4.208                      query.add (new TermQuery (new Term (DocumentUtil.FIELD_FILENAME, fileUrl)),BooleanClause.Occur.MUST);
   4.209  
   4.210 -                    Hits hits = searcher.search(query);
   4.211 -                    for (int i=0; i<hits.length(); i++) {
   4.212 -                        in.deleteDocument (hits.id(i));
   4.213 +                    final BitSet bs = new BitSet();
   4.214 +                    final BitSetCollector bsCollector = new BitSetCollector(bs);
   4.215 +                    searcher.search(query, bsCollector);
   4.216 +                    for (int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) {
   4.217 +                        in.deleteDocument (i);
   4.218                      }
   4.219                  }
   4.220                  in.deleteDocuments (DocumentUtil.rootDocumentTerm());
   4.221 @@ -649,12 +652,6 @@
   4.222              if (debugIndexMerging) {
   4.223                  out.setInfoStream (System.err);
   4.224              }
   4.225 -            final LuceneIndexMBean indexSettings = LuceneIndexMBeanImpl.getDefault();
   4.226 -            if (indexSettings != null) {
   4.227 -                out.setMergeFactor(indexSettings.getMergeFactor());
   4.228 -                out.setMaxMergeDocs(indexSettings.getMaxMergeDocs());
   4.229 -                out.setMaxBufferedDocs(indexSettings.getMaxBufferedDocs());
   4.230 -            }        
   4.231              LowMemoryNotifier lm = LowMemoryNotifier.getDefault();
   4.232              LMListener lmListener = new LMListener ();
   4.233              lm.addLowMemoryListener (lmListener);        
   4.234 @@ -665,7 +662,7 @@
   4.235              }
   4.236              else {
   4.237                  memDir = new RAMDirectory ();
   4.238 -                activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true);
   4.239 +                activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
   4.240              }        
   4.241              try {
   4.242                  activeOut.addDocument (DocumentUtil.createRootTimeStampDocument (timeStamp));
   4.243 @@ -674,16 +671,16 @@
   4.244                          Document newDoc = new Document();
   4.245                          newDoc.add(new Field (DocumentUtil.FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO));
   4.246                          if (document.overrideUrl != null) {
   4.247 -                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, document.overrideUrl, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.248 +                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, document.overrideUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.249                          } else if (filename != null) {
   4.250 -                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.251 +                            newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.252                          }
   4.253  
   4.254                          for (int i = 0, n = document.indexedKeys.size(); i < n; i++) {
   4.255                              String key = document.indexedKeys.get(i);
   4.256                              String value = document.indexedValues.get(i);
   4.257                              assert key != null && value != null : "key=" + key + ", value=" + value;
   4.258 -                            Field field = new Field(key, value, Field.Store.YES, Field.Index.UN_TOKENIZED);
   4.259 +                            Field field = new Field(key, value, Field.Store.YES, Field.Index.NOT_ANALYZED);
   4.260                              newDoc.add(field);
   4.261                          }
   4.262  
   4.263 @@ -700,19 +697,19 @@
   4.264                  } else if (filename != null) {
   4.265                      Document newDoc = new Document();
   4.266                      newDoc.add(new Field (DocumentUtil.FIELD_TIME_STAMP,DateTools.timeToString(timeStamp,DateTools.Resolution.MILLISECOND),Field.Store.YES,Field.Index.NO));
   4.267 -                    newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.UN_TOKENIZED));
   4.268 +                    newDoc.add(new Field (DocumentUtil.FIELD_FILENAME, filename, Field.Store.YES, Field.Index.NOT_ANALYZED));
   4.269                      activeOut.addDocument(newDoc);
   4.270                  }
   4.271  
   4.272                  if (memDir != null && lmListener.lowMemory.getAndSet(false)) {                       
   4.273                      activeOut.close();
   4.274 -                    out.addIndexes(new Directory[] {memDir});                        
   4.275 +                    out.addIndexesNoOptimize(new Directory[] {memDir});                        
   4.276                      memDir = new RAMDirectory ();        
   4.277 -                    activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true);
   4.278 +                    activeOut = new IndexWriter (memDir,new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
   4.279                  }
   4.280                  if (memDir != null) {
   4.281                      activeOut.close();
   4.282 -                    out.addIndexes(new Directory[] {memDir});   
   4.283 +                    out.addIndexesNoOptimize(new Directory[] {memDir});   
   4.284                      activeOut = null;
   4.285                      memDir = null;
   4.286                  }
   4.287 @@ -903,9 +900,7 @@
   4.288          @Override
   4.289          public String toString() {
   4.290              StringBuilder sb = new StringBuilder();
   4.291 -            Enumeration en = doc.fields();
   4.292 -            while (en.hasMoreElements()) {
   4.293 -                Field f = (Field)en.nextElement();
   4.294 +            for (Fieldable f : (List<Fieldable>)doc.getFields()) {    //Remove cast in Lucene 3.x            
   4.295                  sb.append(f.name());
   4.296                  sb.append(":");
   4.297                  sb.append(f.stringValue());
   4.298 @@ -983,9 +978,7 @@
   4.299          @Override
   4.300          public String toString() {
   4.301              StringBuilder sb = new StringBuilder();
   4.302 -            Enumeration en = doc.fields();
   4.303 -            while (en.hasMoreElements()) {
   4.304 -                Field f = (Field)en.nextElement();
   4.305 +            for (Fieldable f : (List<Fieldable>)doc.getFields()) {        //Remove cast in Lucene 3.x
   4.306                  if (f.name().equals(primaryKey)) {
   4.307                      sb.append(primaryKey);
   4.308                      sb.append(":");
   4.309 @@ -1027,6 +1020,40 @@
   4.310          }
   4.311      }
   4.312      
   4.313 +    
   4.314 +    private static class BitSetCollector extends Collector {
   4.315 +
   4.316 +        private int docBase;
   4.317 +        public final BitSet bits;
   4.318 +
   4.319 +        BitSetCollector(final BitSet bitSet) {
   4.320 +            assert bitSet != null;
   4.321 +            bits = bitSet;
   4.322 +        }
   4.323 +
   4.324 +        // ignore scorer
   4.325 +        @Override
   4.326 +        public void setScorer(Scorer scorer) {
   4.327 +        }
   4.328 +
   4.329 +        // accept docs out of order (for a BitSet it doesn't matter)
   4.330 +        @Override
   4.331 +        public boolean acceptsDocsOutOfOrder() {
   4.332 +          return true;
   4.333 +        }
   4.334 +
   4.335 +        @Override
   4.336 +        public void collect(int doc) {
   4.337 +          bits.set(doc + docBase);
   4.338 +        }
   4.339 +
   4.340 +        @Override
   4.341 +        public void setNextReader(IndexReader reader, int docBase) {
   4.342 +          this.docBase = docBase;
   4.343 +        }
   4.344 +
   4.345 +    }
   4.346 +    
   4.347      private <T> void gsfEmptyPrefixSearch (final IndexReader in, final Set<SearchResult> result, 
   4.348                                          final Set<String> terms) throws IOException {
   4.349          final int bound = in.maxDoc();
     5.1 --- a/gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndexMBean.java	Tue Jan 18 10:17:10 2011 -0500
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,71 +0,0 @@
     5.4 -/*
     5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 - *
     5.7 - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
     5.8 - *
     5.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    5.10 - * Other names may be trademarks of their respective owners.
    5.11 - *
    5.12 - * The contents of this file are subject to the terms of either the GNU
    5.13 - * General Public License Version 2 only ("GPL") or the Common
    5.14 - * Development and Distribution License("CDDL") (collectively, the
    5.15 - * "License"). You may not use this file except in compliance with the
    5.16 - * License. You can obtain a copy of the License at
    5.17 - * http://www.netbeans.org/cddl-gplv2.html
    5.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.19 - * specific language governing permissions and limitations under the
    5.20 - * License.  When distributing the software, include this License Header
    5.21 - * Notice in each file and include the License file at
    5.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    5.23 - * particular file as subject to the "Classpath" exception as provided
    5.24 - * by Oracle in the GPL Version 2 section of the License file that
    5.25 - * accompanied this code. If applicable, add the following below the
    5.26 - * License Header, with the fields enclosed by brackets [] replaced by
    5.27 - * your own identifying information:
    5.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    5.29 - *
    5.30 - * Contributor(s):
    5.31 - *
    5.32 - * The Original Software is NetBeans. The Initial Developer of the Original
    5.33 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    5.34 - * Microsystems, Inc. All Rights Reserved.
    5.35 - *
    5.36 - * If you wish your version of this file to be governed by only the CDDL
    5.37 - * or only the GPL Version 2, indicate your decision by adding
    5.38 - * "[Contributor] elects to include this software in this distribution
    5.39 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.40 - * single choice of license, a recipient has the option to distribute
    5.41 - * your version of this file under either the CDDL, the GPL Version 2 or
    5.42 - * to extend the choice of license to its licensees as provided above.
    5.43 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.44 - * Version 2 license, then the option applies only if the new code is
    5.45 - * made subject to such option by the copyright holder.
    5.46 - */
    5.47 -
    5.48 -package org.netbeans.modules.gsfret.source.usages;
    5.49 -
    5.50 -/**
    5.51 - * This file is originally from Retouche, the Java Support
    5.52 - * infrastructure in NetBeans. I have modified the file as little
    5.53 - * as possible to make merging Retouche fixes back as simple as
    5.54 - * possible. 
    5.55 - *
    5.56 - *
    5.57 - * @author Tomas Zezula
    5.58 - */
    5.59 -public interface LuceneIndexMBean {
    5.60 -
    5.61 -    public static final String OBJECT_NAME = "org.netbeans.modules.java.source:type=LuceneIndex";     //NOI18N
    5.62 -
    5.63 -    public int getMergeFactor ();
    5.64 -
    5.65 -    public void setMergeFactor (int mf);
    5.66 -
    5.67 -    public int getMaxMergeDocs ();
    5.68 -
    5.69 -    public void setMaxMergeDocs (int nd);
    5.70 -
    5.71 -    public int getMaxBufferedDocs ();
    5.72 -
    5.73 -    public void setMaxBufferedDocs (int nd);
    5.74 -}
     6.1 --- a/gsf/src/org/netbeans/modules/gsfret/source/usages/LuceneIndexMBeanImpl.java	Tue Jan 18 10:17:10 2011 -0500
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,107 +0,0 @@
     6.4 -/*
     6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.6 - *
     6.7 - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
     6.8 - *
     6.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    6.10 - * Other names may be trademarks of their respective owners.
    6.11 - *
    6.12 - * The contents of this file are subject to the terms of either the GNU
    6.13 - * General Public License Version 2 only ("GPL") or the Common
    6.14 - * Development and Distribution License("CDDL") (collectively, the
    6.15 - * "License"). You may not use this file except in compliance with the
    6.16 - * License. You can obtain a copy of the License at
    6.17 - * http://www.netbeans.org/cddl-gplv2.html
    6.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    6.19 - * specific language governing permissions and limitations under the
    6.20 - * License.  When distributing the software, include this License Header
    6.21 - * Notice in each file and include the License file at
    6.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    6.23 - * particular file as subject to the "Classpath" exception as provided
    6.24 - * by Oracle in the GPL Version 2 section of the License file that
    6.25 - * accompanied this code. If applicable, add the following below the
    6.26 - * License Header, with the fields enclosed by brackets [] replaced by
    6.27 - * your own identifying information:
    6.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    6.29 - *
    6.30 - * Contributor(s):
    6.31 - *
    6.32 - * The Original Software is NetBeans. The Initial Developer of the Original
    6.33 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    6.34 - * Microsystems, Inc. All Rights Reserved.
    6.35 - *
    6.36 - * If you wish your version of this file to be governed by only the CDDL
    6.37 - * or only the GPL Version 2, indicate your decision by adding
    6.38 - * "[Contributor] elects to include this software in this distribution
    6.39 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    6.40 - * single choice of license, a recipient has the option to distribute
    6.41 - * your version of this file under either the CDDL, the GPL Version 2 or
    6.42 - * to extend the choice of license to its licensees as provided above.
    6.43 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    6.44 - * Version 2 license, then the option applies only if the new code is
    6.45 - * made subject to such option by the copyright holder.
    6.46 - */
    6.47 -
    6.48 -package org.netbeans.modules.gsfret.source.usages;
    6.49 -import javax.management.NotCompliantMBeanException;
    6.50 -import javax.management.StandardMBean;
    6.51 -import org.apache.lucene.index.IndexWriter;
    6.52 -import org.openide.ErrorManager;
    6.53 -
    6.54 -/**
    6.55 - * This file is originally from Retouche, the Java Support 
    6.56 - * infrastructure in NetBeans. I have modified the file as little
    6.57 - * as possible to make merging Retouche fixes back as simple as
    6.58 - * possible. 
    6.59 - *
    6.60 - *
    6.61 - * @author Tomas Zezula
    6.62 - */
    6.63 -public class LuceneIndexMBeanImpl extends StandardMBean implements LuceneIndexMBean {
    6.64 -
    6.65 -    private static LuceneIndexMBeanImpl instance;
    6.66 -
    6.67 -    private int mergeFactor = IndexWriter.DEFAULT_MERGE_FACTOR;
    6.68 -    private int maxMergeDocs = IndexWriter.DEFAULT_MAX_MERGE_DOCS;
    6.69 -    private int maxBufferedDocs = IndexWriter.DEFAULT_MAX_BUFFERED_DOCS;
    6.70 -
    6.71 -    private LuceneIndexMBeanImpl () throws NotCompliantMBeanException {
    6.72 -        super (LuceneIndexMBean.class);
    6.73 -    }
    6.74 -    
    6.75 -    public int getMergeFactor () {
    6.76 -        return this.mergeFactor;
    6.77 -    }
    6.78 -    
    6.79 -    public void setMergeFactor (int mf) {
    6.80 -        this.mergeFactor = mf;
    6.81 -    }
    6.82 -    
    6.83 -    public int getMaxMergeDocs () {
    6.84 -        return this.maxMergeDocs;
    6.85 -    }
    6.86 -    
    6.87 -    public void setMaxMergeDocs (int nd) {
    6.88 -        this.maxMergeDocs = nd;
    6.89 -    }
    6.90 -    
    6.91 -    public int getMaxBufferedDocs () {
    6.92 -        return this.maxBufferedDocs;
    6.93 -    }
    6.94 -    
    6.95 -    public void setMaxBufferedDocs (int nd) {
    6.96 -        this.maxBufferedDocs = nd;
    6.97 -    }
    6.98 -    
    6.99 -    public static synchronized LuceneIndexMBeanImpl getDefault () {
   6.100 -        if (instance == null) {
   6.101 -            try {
   6.102 -                instance = new LuceneIndexMBeanImpl ();            
   6.103 -            } catch (NotCompliantMBeanException e) {
   6.104 -                ErrorManager.getDefault().notify(e);                
   6.105 -            }
   6.106 -        }
   6.107 -        return instance;
   6.108 -    }
   6.109 -    
   6.110 -}