Revision: 17512
          http://sourceforge.net/p/gate/code/17512
Author:   markagreenwood
Date:     2014-03-03 15:52:18 +0000 (Mon, 03 Mar 2014)
Log Message:
-----------
updated the code to use the new IndexWriter constructor -- the outcome should 
be identical as I've used the code from within the deprecated constructor that 
we were previously using

Modified Paths:
--------------
    gate/trunk/src/main/gate/creole/ir/lucene/LuceneIndexManager.java

Modified: gate/trunk/src/main/gate/creole/ir/lucene/LuceneIndexManager.java
===================================================================
--- gate/trunk/src/main/gate/creole/ir/lucene/LuceneIndexManager.java   
2014-03-03 15:29:31 UTC (rev 17511)
+++ gate/trunk/src/main/gate/creole/ir/lucene/LuceneIndexManager.java   
2014-03-03 15:52:18 UTC (rev 17512)
@@ -31,6 +31,8 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.util.Version;
 
@@ -81,12 +83,18 @@
       corpus.getFeatures().put(CORPUS_INDEX_FEATURE, 
CORPUS_INDEX_FEATURE_VALUE);
       /* End */
 
-      IndexWriter writer = new IndexWriter(
+      IndexWriter writer =
+              new IndexWriter(FSDirectory.open(new File(location)),
+                      new IndexWriterConfig(Version.LUCENE_31,
+                              new SimpleAnalyzer(Version.LUCENE_30))
+                              .setOpenMode(OpenMode.CREATE));
+      
+      /*IndexWriter writer = new IndexWriter(
               FSDirectory.open(new File(location)),
               new SimpleAnalyzer(Version.LUCENE_30), 
               true,
               new 
IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)
-              );
+              );*/
 
       for(int i = 0; i<corpus.size(); i++) {
         boolean isLoaded = corpus.isDocumentLoaded(i);
@@ -115,12 +123,22 @@
     if(indexDefinition == null)
       throw new GateRuntimeException("Index definition is null!");
     try {
-      IndexWriter writer = new IndexWriter(
+
+      IndexWriter writer =
+              new IndexWriter(FSDirectory.open(new 
File(indexDefinition.getIndexLocation())),
+                      new IndexWriterConfig(Version.LUCENE_31,
+                              new SimpleAnalyzer(Version.LUCENE_30))
+                              .setOpenMode(OpenMode.APPEND));
+      
+      /*IndexWriter writer = new IndexWriter(
               FSDirectory.open(new File(indexDefinition.getIndexLocation())),
               new SimpleAnalyzer(Version.LUCENE_30), 
               false,
-              new 
IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));
-      writer.optimize();
+              new 
IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));*/
+      
+      //writer.optimize();
+      writer.forceMerge(1, true);
+      
       writer.commit();
       writer.close();
     } catch (java.io.IOException ioe){
@@ -173,12 +191,17 @@
 
       reader.close();
 
-      IndexWriter writer = new IndexWriter(
+      /*IndexWriter writer = new IndexWriter(
               FSDirectory.open(new File(location)),
               new SimpleAnalyzer(Version.LUCENE_30), 
               false,
               new 
IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)
-              );
+              );*/
+      IndexWriter writer =
+              new IndexWriter(FSDirectory.open(new File(location)),
+                      new IndexWriterConfig(Version.LUCENE_31,
+                              new SimpleAnalyzer(Version.LUCENE_30))
+                              .setOpenMode(OpenMode.APPEND));      
 
       for(int i = 0; i<added.size(); i++) {
         gate.Document gateDoc = (gate.Document) added.get(i);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to