KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > search > LuceneCocoonHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 /**
28  * This class encapsulates some helper methods.
29  *
30  * @author <a HREF="mailto:berni_huber@a1.net">Bernhard Huber</a>
31  * @version CVS $Id: LuceneCocoonHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

33 public class LuceneCocoonHelper
34 {
35     /**
36      *Gets the directory attribute of the LuceneCocoonHelper class
37      *
38      * @param directory Description of Parameter
39      * @param create Description of Parameter
40      * @return The directory value
41      * @exception IOException Description of Exception
42      * @since
43      */

44     public static Directory getDirectory(File JavaDoc directory, boolean create) throws IOException JavaDoc {
45         FSDirectory fsDirectory = FSDirectory.getDirectory(directory, create);
46         return fsDirectory;
47     }
48
49     /**
50      *Gets the analyzer attribute of the LuceneCocoonHelper class
51      *
52      * @param analyzer_class_name Description of Parameter
53      * @return The analyzer value
54      * @since
55      */

56     public static Analyzer getAnalyzer(String JavaDoc analyzer_class_name) {
57         Analyzer analyzer = null;
58         try {
59             Class JavaDoc analyzer_class = Class.forName(analyzer_class_name);
60             analyzer = (Analyzer) analyzer_class.newInstance();
61         } catch (Exception JavaDoc e) {
62         }
63         return analyzer;
64     }
65
66     /**
67      *Gets the indexReader attribute of the LuceneCocoonHelper class
68      *
69      * @param directory Description of Parameter
70      * @return The indexReader value
71      * @exception IOException Description of Exception
72      * @since
73      */

74     public static IndexReader getIndexReader(Directory directory) throws IOException JavaDoc {
75         IndexReader reader = IndexReader.open(directory);
76         return reader;
77     }
78
79     /**
80      *Gets the indexWriter attribute of the LuceneCocoonHelper class
81      *
82      * @param index Description of Parameter
83      * @param analyzer Description of Parameter
84      * @param create Description of Parameter
85      * @return The indexWriter value
86      * @exception IOException Description of Exception
87      * @since
88      */

89     public static IndexWriter getIndexWriter(Directory index, Analyzer analyzer, boolean create) throws IOException JavaDoc {
90         IndexWriter writer = new IndexWriter(index, analyzer, create);
91         return writer;
92     }
93 }
94
95
Popular Tags