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