KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > wrapper > lucene > LuceneIndexer


1 package org.enhydra.snapper.wrapper.lucene;
2
3
4 /**
5  */

6
7 import org.apache.lucene.analysis.standard.StandardAnalyzer;
8 //import org.apache.lucene.document.Document;
9
import org.apache.lucene.index.IndexWriter;
10 import org.enhydra.snapper.api.Indexer;
11
12 import java.io.*;
13
14
15 public class LuceneIndexer implements Indexer{
16     
17     IndexWriter writer;
18     File originalFile;
19     String JavaDoc contents;
20     long age, size;
21     int maxSize;
22     
23     public LuceneIndexer() {}
24     
25     
26     // implementirati razlicite Analyzer-e kao parametar koji se ovde prosledjuje metodi
27
public void setUpIndexer(String JavaDoc siteName, String JavaDoc language, boolean create, int maxLength) {
28         try {
29           writer = new IndexWriter(siteName, new StandardAnalyzer(), create);
30           this.maxSize = maxLength;
31         }
32         catch (IOException e) {
33             try{
34                 LuceneIndexerFactory.logger.error("Could not initialize Indexer");
35             } catch (Exception JavaDoc ex) {System.out.println(" caught a " + e.getClass() +
36                    "\n with message: " + e.getMessage());
37             }
38           
39         }
40   }
41     public void setMaxAge(String JavaDoc age){
42         this.age = Long.parseLong(age);
43     }
44     public void setMaxSize(String JavaDoc size){
45         this.size = Long.parseLong(size);
46     }
47     
48     public void optimize()
49     {
50         try{
51               writer.optimize();
52             }
53             catch (IOException e) {
54                 try{
55                     LuceneIndexerFactory.logger.error("Could not optimize Indexer");
56                 } catch (Exception JavaDoc ex) {System.out.println(" caught a " + e.getClass() +
57                        "\n with message: " + e.getMessage());
58                 }
59             }
60     }
61     
62     public void close()
63     {
64         try{
65           writer.close();
66         }
67         catch (IOException e) {
68             try{
69                 LuceneIndexerFactory.logger.error("Could not close Indexer");
70             } catch (Exception JavaDoc ex) {System.out.println(" caught a " + e.getClass() +
71                    "\n with message: " + e.getMessage());
72             }
73         }
74     }
75     
76     public void indexDoc(long timestamp, String JavaDoc path, String JavaDoc text, String JavaDoc type, String JavaDoc title, String JavaDoc properties, String JavaDoc metadata, String JavaDoc fileName) throws IOException
77     {
78     try{
79             
80         writer.addDocument(FileDocument.Document(timestamp, path, text, type, title, maxSize, properties, metadata, fileName));
81         } catch (IOException e) {
82             try{
83                 LuceneIndexerFactory.logger.error("Could not add document to Indexer");
84             } catch (Exception JavaDoc ex) {System.out.println(" caught a " + e.getClass() +
85                    "\n with message: " + e.getMessage());
86             }
87         }
88     }
89     
90 // public void indexDoc(File file, String text, String type, String title, String properties, String metadata) throws IOException
91
// {
92
// try{
93
// writer.addDocument(FileDocument.Document(file, text, type, title, maxSize, properties, metadata));
94
// } catch (IOException e) {
95
// try{
96
// LuceneIndexerFactory.logger.error("Could not add document to Indexer");
97
// } catch (Exception ex) {System.out.println(" caught a " + e.getClass() +
98
// "\n with message: " + e.getMessage());
99
// }
100
// }
101
// }
102

103
104     
105     
106   }
107
Popular Tags