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:
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.search.IndexManagerImpl;
29: import org.apache.roller.business.search.FieldConstants;
30: import org.apache.roller.business.Roller;
31: import org.apache.roller.business.RollerFactory;
32: import org.apache.roller.pojos.WeblogEntryData;
33:
34: /**
35: * An operation that adds a new log entry into the index.
36: * @author Mindaugas Idzelis (min@idzelis.com)
37: */
38: public class ReIndexEntryOperation extends WriteToIndexOperation {
39:
40: //~ Static fields/initializers =============================================
41:
42: private static Log mLogger = LogFactory.getFactory().getInstance(
43: AddEntryOperation.class);
44:
45: //~ Instance fields ========================================================
46:
47: private WeblogEntryData data;
48:
49: //~ Constructors ===========================================================
50:
51: /**
52: * Adds a web log entry into the index.
53: */
54: public ReIndexEntryOperation(IndexManagerImpl mgr,
55: WeblogEntryData data) {
56: super (mgr);
57: this .data = data;
58: }
59:
60: //~ Methods ================================================================
61:
62: public void doRun() {
63: IndexReader reader = beginDeleting();
64: try {
65: if (reader != null) {
66: Term term = new Term(FieldConstants.ID, data.getId());
67: reader.delete(term);
68: }
69: } catch (IOException e) {
70: mLogger.error("Error deleting doc from index", e);
71: } finally {
72: endDeleting();
73: }
74:
75: IndexWriter writer = beginWriting();
76: Roller roller = RollerFactory.getRoller();
77: try {
78: if (writer != null) {
79: writer.addDocument(getDocument(data));
80: }
81: } catch (IOException e) {
82: mLogger.error("Problems adding doc to index", e);
83: } finally {
84: if (roller != null)
85: roller.release();
86: endWriting();
87: }
88: }
89: }
|