1 package org.enhydra.snapper.wrapper.lucene; 2 3 4 6 7 import org.apache.lucene.analysis.standard.StandardAnalyzer; 8 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 contents; 20 long age, size; 21 int maxSize; 22 23 public LuceneIndexer() {} 24 25 26 public void setUpIndexer(String siteName, String 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 ex) {System.out.println(" caught a " + e.getClass() + 36 "\n with message: " + e.getMessage()); 37 } 38 39 } 40 } 41 public void setMaxAge(String age){ 42 this.age = Long.parseLong(age); 43 } 44 public void setMaxSize(String 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 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 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 path, String text, String type, String title, String properties, String metadata, String 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 ex) {System.out.println(" caught a " + e.getClass() + 85 "\n with message: " + e.getMessage()); 86 } 87 } 88 } 89 90 103 104 105 106 } 107 | Popular Tags |