camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: After the upgrade to Lucene 4.4.0, better make use of constants for the values which are fixed/frozen.
Date Tue, 01 Oct 2013 05:44:34 GMT
Updated Branches:
  refs/heads/master ff41bd54b -> c38e1dc0f


After the upgrade to Lucene 4.4.0, better make use of constants for the values which are fixed/frozen.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c38e1dc0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c38e1dc0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c38e1dc0

Branch: refs/heads/master
Commit: c38e1dc0f76f7848f26de90879ad16d5a17aa23e
Parents: ff41bd5
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Tue Oct 1 07:44:22 2013 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Tue Oct 1 07:44:22 2013 +0200

----------------------------------------------------------------------
 .../camel/component/lucene/LuceneIndexer.java   | 31 ++++++++++----------
 1 file changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c38e1dc0/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
----------------------------------------------------------------------
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
index 7e0fade..d5e793c 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
@@ -37,9 +37,10 @@ import org.slf4j.LoggerFactory;
 
 public class LuceneIndexer {
     private static final Logger LOG = LoggerFactory.getLogger(LuceneIndexer.class);
+    private static final FieldType TOKENIZED_FIELD_TYPE = createFieldType(true);
+    private static final FieldType NON_TOKENIZED_FIELD_TYPE = createFieldType(false);
+
     private File sourceDirectory;
-    private FieldType fieldTypeAnalyzed;
-    private FieldType fieldTypeUnanalyzed;
     private Analyzer analyzer;
     private NIOFSDirectory niofsDirectory;
     private IndexWriter indexWriter;
@@ -54,18 +55,6 @@ public class LuceneIndexer {
         } else {
             this.setNiofsDirectory(new NIOFSDirectory(new File("./indexDirectory")));
         }
-        
-        fieldTypeAnalyzed = new FieldType();
-        fieldTypeAnalyzed.setIndexed(true);
-        fieldTypeAnalyzed.setStored(true);
-        fieldTypeAnalyzed.setTokenized(true);
-        fieldTypeAnalyzed.freeze();
-
-        fieldTypeUnanalyzed = new FieldType();
-        fieldTypeUnanalyzed.setIndexed(true);
-        fieldTypeUnanalyzed.setStored(true);
-        fieldTypeUnanalyzed.setTokenized(false);
-        fieldTypeUnanalyzed.freeze();
 
         this.setAnalyzer(analyzer);
         
@@ -122,7 +111,7 @@ public class LuceneIndexer {
         }
 
         Document doc = new Document();
-        doc.add(new Field(field, value, analyzed ? fieldTypeAnalyzed : fieldTypeUnanalyzed));
+        doc.add(new Field(field, value, analyzed ? TOKENIZED_FIELD_TYPE : NON_TOKENIZED_FIELD_TYPE));
         indexWriter.addDocument(doc);
     }
 
@@ -164,4 +153,16 @@ public class LuceneIndexer {
         indexWriter.close();
     }
 
+    private static FieldType createFieldType(boolean tokenized) {
+        FieldType answer = new FieldType();
+        answer.setIndexed(true);
+        answer.setStored(true);
+        answer.setTokenized(tokenized);
+
+        // freeze the answer so that it becomes immutable
+        answer.freeze();
+
+        return answer;
+    }
+
 }


Mime
View raw message