1 6 package org.roller.business.search.operations; 7 8 import java.io.IOException ; 9 import java.util.Date ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.apache.lucene.index.IndexReader; 14 import org.apache.lucene.index.Term; 15 import org.roller.business.IndexManagerImpl; 16 import org.roller.business.search.FieldConstants; 17 import org.roller.business.search.IndexUtil; 18 import org.roller.pojos.UserData; 19 20 21 26 public class RemoveUserIndexOperation extends WriteToIndexOperation 27 { 28 30 private static Log mLogger = 31 LogFactory.getFactory().getInstance(RemoveUserIndexOperation.class); 32 33 35 private UserData user; 36 37 39 44 public RemoveUserIndexOperation(IndexManagerImpl mgr, UserData user) 45 { 46 super(mgr); 47 this.user = user; 48 } 49 50 52 55 public void doRun() 56 { 57 Date start = new Date (); 58 59 IndexReader reader = beginDeleting(); 60 61 try 62 { 63 if (reader != null) 64 { 65 String userName = null; 66 if (user != null) 67 { 68 userName = user.getUserName(); 69 } 70 Term tUsername = 71 IndexUtil.getTerm(FieldConstants.USERNAME, userName); 72 73 if (tUsername != null) 74 { 75 reader.delete(tUsername); 76 } 77 } 78 } 79 catch (IOException e) 80 { 81 mLogger.info("Problems deleting doc from index", e); 82 } 83 finally 84 { 85 endDeleting(); 86 } 87 88 Date end = new Date (); 89 double length = (end.getTime() - start.getTime()) / (double) 1000; 90 91 if (user != null) 92 { 93 mLogger.info("Completed deleting indices for '" + 94 user.getUserName() + "' in '" + length + "' seconds"); 95 } 96 } 97 } 98 | Popular Tags |