KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > search > operations > RemoveUserIndexOperation


1 /*
2  * Created on Jul 16, 2003
3  *
4  * Authored by: Mindaugas Idzelis (min@idzelis.com)
5  */

6 package org.roller.business.search.operations;
7
8 import java.io.IOException JavaDoc;
9 import java.util.Date JavaDoc;
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 /**
22  * @author aim4min
23  *
24  * An index operation that rebuilds a given users index (or all indexes.)
25  */

26 public class RemoveUserIndexOperation extends WriteToIndexOperation
27 {
28     //~ Static fields/initializers =============================================
29

30     private static Log mLogger =
31         LogFactory.getFactory().getInstance(RemoveUserIndexOperation.class);
32
33     //~ Instance fields ========================================================
34

35     private UserData user;
36
37     //~ Constructors ===========================================================
38

39     /**
40      * Create a new operation that will recreate an index.
41      *
42      * @param website The website to rebuild the index for, or null for all users.
43      */

44     public RemoveUserIndexOperation(IndexManagerImpl mgr, UserData user)
45     {
46         super(mgr);
47         this.user = user;
48     }
49
50     //~ Methods ================================================================
51

52     /* (non-Javadoc)
53      * @see java.lang.Runnable#run()
54      */

55     public void doRun()
56     {
57         Date JavaDoc start = new Date JavaDoc();
58
59         IndexReader reader = beginDeleting();
60
61         try
62         {
63             if (reader != null)
64             {
65                 String JavaDoc 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 JavaDoc e)
80         {
81             mLogger.info("Problems deleting doc from index", e);
82         }
83         finally
84         {
85             endDeleting();
86         }
87
88         Date JavaDoc end = new Date JavaDoc();
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