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