KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > business > search > operations > RemoveWebsiteIndexOperation


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18 /* Created on Jul 16, 2003 */
19 package org.apache.roller.business.search.operations;
20
21 import java.io.IOException JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.lucene.index.IndexReader;
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.business.search.IndexUtil;
31 import org.apache.roller.pojos.WebsiteData;
32
33
34 /**
35  * An index operation that rebuilds a given users index (or all indexes).
36  * @author Mindaugas Idzelis (min@idzelis.com)
37  */

38 public class RemoveWebsiteIndexOperation extends WriteToIndexOperation {
39     
40     //~ Static fields/initializers =============================================
41

42     private static Log mLogger =
43             LogFactory.getFactory().getInstance(RemoveWebsiteIndexOperation.class);
44     
45     //~ Instance fields ========================================================
46

47     private WebsiteData website;
48     
49     //~ Constructors ===========================================================
50

51     /**
52      * Create a new operation that will recreate an index.
53      * @param website The website to rebuild the index for, or null for all sites.
54      */

55     public RemoveWebsiteIndexOperation(IndexManagerImpl mgr, WebsiteData website) {
56         super(mgr);
57         this.website = website;
58     }
59     
60     //~ Methods ================================================================
61

62     public void doRun() {
63         Date JavaDoc start = new Date JavaDoc();
64         IndexReader reader = beginDeleting();
65         try {
66             if (reader != null) {
67                 String JavaDoc handle = null;
68                 if (website != null) {
69                     handle = website.getHandle();
70                 }
71                 Term tHandle =
72                         IndexUtil.getTerm(FieldConstants.WEBSITE_HANDLE, handle);
73                 
74                 if (tHandle != null) {
75                     reader.delete(tHandle);
76                 }
77             }
78         } catch (IOException JavaDoc e) {
79             mLogger.info("Problems deleting doc from index", e);
80         } finally {
81             endDeleting();
82         }
83         
84         Date JavaDoc end = new Date JavaDoc();
85         double length = (end.getTime() - start.getTime()) / (double) 1000;
86         
87         if (website != null) {
88             mLogger.info("Completed deleting indices for website '" +
89                     website.getName() + "' in '" + length + "' seconds");
90         }
91     }
92 }
93
Popular Tags