01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
22: import java.util.Date;
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.search.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: * An index operation that rebuilds a given users index (or all indexes).
35: * @author Mindaugas Idzelis (min@idzelis.com)
36: */
37: public class RemoveWebsiteIndexOperation extends WriteToIndexOperation {
38:
39: //~ Static fields/initializers =============================================
40:
41: private static Log mLogger = LogFactory.getFactory().getInstance(
42: RemoveWebsiteIndexOperation.class);
43:
44: //~ Instance fields ========================================================
45:
46: private WebsiteData website;
47:
48: //~ Constructors ===========================================================
49:
50: /**
51: * Create a new operation that will recreate an index.
52: * @param website The website to rebuild the index for, or null for all sites.
53: */
54: public RemoveWebsiteIndexOperation(IndexManagerImpl mgr,
55: WebsiteData website) {
56: super (mgr);
57: this .website = website;
58: }
59:
60: //~ Methods ================================================================
61:
62: public void doRun() {
63: Date start = new Date();
64: IndexReader reader = beginDeleting();
65: try {
66: if (reader != null) {
67: String handle = null;
68: if (website != null) {
69: handle = website.getHandle();
70: }
71: Term tHandle = IndexUtil.getTerm(
72: FieldConstants.WEBSITE_HANDLE, handle);
73:
74: if (tHandle != null) {
75: reader.delete(tHandle);
76: }
77: }
78: } catch (IOException e) {
79: mLogger.info("Problems deleting doc from index", e);
80: } finally {
81: endDeleting();
82: }
83:
84: Date end = new Date();
85: double length = (end.getTime() - start.getTime())
86: / (double) 1000;
87:
88: if (website != null) {
89: mLogger.info("Completed deleting indices for website '"
90: + website.getName() + "' in '" + length
91: + "' seconds");
92: }
93: }
94: }
|