You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/03/09 02:51:22 UTC
svn commit: r1826292 -
/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java
Author: tilman
Date: Fri Mar 9 02:51:21 2018
New Revision: 1826292
URL: http://svn.apache.org/viewvc?rev=1826292&view=rev
Log:
PDFBOX-4071: use jdk7 try-with-resources
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java?rev=1826292&r1=1826291&r2=1826292&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/lucene/IndexPDFFiles.java Fri Mar 9 02:51:21 2018
@@ -102,44 +102,41 @@ public final class IndexPDFFiles
{
System.out.println("Indexing to directory '" + indexPath + "'...");
- Directory dir = FSDirectory.open(new File(indexPath).toPath());
- Analyzer analyzer = new StandardAnalyzer();
- IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
-
- if (create)
- {
- // Create a new index in the directory, removing any
- // previously indexed documents:
- iwc.setOpenMode(OpenMode.CREATE);
- }
- else
+ try (Directory dir = FSDirectory.open(new File(indexPath).toPath()))
{
- // Add new documents to an existing index:
- iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
- }
-
- // Optional: for better indexing performance, if you
- // are indexing many documents, increase the RAM
- // buffer. But if you do this, increase the max heap
- // size to the JVM (eg add -Xmx512m or -Xmx1g):
- //
- // iwc.setRAMBufferSizeMB(256.0);
- try (IndexWriter writer = new IndexWriter(dir, iwc))
- {
- indexDocs(writer, docDir);
-
- // NOTE: if you want to maximize search performance,
- // you can optionally call forceMerge here. This can be
- // a terribly costly operation, so generally it's only
- // worth it when your index is relatively static (ie
- // you're done adding documents to it):
+ Analyzer analyzer = new StandardAnalyzer();
+ IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
+ if (create)
+ {
+ // Create a new index in the directory, removing any
+ // previously indexed documents:
+ iwc.setOpenMode(OpenMode.CREATE);
+ }
+ else
+ {
+ // Add new documents to an existing index:
+ iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
+ }
+ // Optional: for better indexing performance, if you
+ // are indexing many documents, increase the RAM
+ // buffer. But if you do this, increase the max heap
+ // size to the JVM (eg add -Xmx512m or -Xmx1g):
//
- // writer.forceMerge(1);
+ // iwc.setRAMBufferSizeMB(256.0);
+ try (final IndexWriter writer = new IndexWriter(dir, iwc))
+ {
+ indexDocs(writer, docDir);
+
+ // NOTE: if you want to maximize search performance,
+ // you can optionally call forceMerge here. This can be
+ // a terribly costly operation, so generally it's only
+ // worth it when your index is relatively static (ie
+ // you're done adding documents to it):
+ //
+ // writer.forceMerge(1);
+ }
}
- // When done close the directory
- dir.close();
-
Date end = new Date();
System.out.println(end.getTime() - start.getTime() + " total milliseconds");