1 6 package org.roller.business.search.operations; 7 8 import java.io.IOException ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.apache.lucene.index.IndexReader; 13 import org.apache.lucene.index.IndexWriter; 14 import org.apache.lucene.index.Term; 15 import org.roller.business.IndexManagerImpl; 16 import org.roller.business.search.FieldConstants; 17 import org.roller.model.Roller; 18 import org.roller.model.RollerFactory; 19 import org.roller.pojos.WeblogEntryData; 20 21 26 public class ReIndexEntryOperation extends WriteToIndexOperation 27 { 28 30 private static Log mLogger = 31 LogFactory.getFactory().getInstance(AddEntryOperation.class); 32 33 35 private WeblogEntryData data; 36 37 39 42 public ReIndexEntryOperation(IndexManagerImpl mgr, WeblogEntryData data) 43 { 44 super(mgr); 45 this.data = data; 46 } 47 48 50 53 public void doRun() 54 { 55 IndexReader reader = beginDeleting(); 56 try 57 { 58 if (reader != null) 59 { 60 Term term = new Term(FieldConstants.ID, data.getId()); 61 reader.delete(term); 62 } 63 } 64 catch (IOException e) 65 { 66 mLogger.error("Error deleting doc from index", e); 67 } 68 finally 69 { 70 endDeleting(); 71 } 72 73 IndexWriter writer = beginWriting(); 74 Roller roller = RollerFactory.getRoller(); 75 try 76 { 77 if (writer != null) 78 { 79 writer.addDocument(getDocument(data)); 80 } 81 } 82 catch (IOException e) 83 { 84 mLogger.error("Problems adding doc to index", e); 85 } 86 finally 87 { 88 if (roller != null) roller.release(); 89 endWriting(); 90 } 91 } 92 } 93 | Popular Tags |