1 16 package org.apache.cocoon.components.search; 17 18 import org.apache.lucene.analysis.Analyzer; 19 import org.apache.lucene.index.IndexReader; 20 import org.apache.lucene.index.IndexWriter; 21 import org.apache.lucene.store.Directory; 22 import org.apache.lucene.store.FSDirectory; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 27 33 public class LuceneCocoonHelper 34 { 35 44 public static Directory getDirectory(File directory, boolean create) throws IOException { 45 FSDirectory fsDirectory = FSDirectory.getDirectory(directory, create); 46 return fsDirectory; 47 } 48 49 56 public static Analyzer getAnalyzer(String analyzer_class_name) { 57 Analyzer analyzer = null; 58 try { 59 Class analyzer_class = Class.forName(analyzer_class_name); 60 analyzer = (Analyzer) analyzer_class.newInstance(); 61 } catch (Exception e) { 62 } 63 return analyzer; 64 } 65 66 74 public static IndexReader getIndexReader(Directory directory) throws IOException { 75 IndexReader reader = IndexReader.open(directory); 76 return reader; 77 } 78 79 89 public static IndexWriter getIndexWriter(Directory index, Analyzer analyzer, boolean create) throws IOException { 90 IndexWriter writer = new IndexWriter(index, analyzer, create); 91 return writer; 92 } 93 } 94 95 | Popular Tags |