001: /*
002:
003: * LIUS - Lucene Index Update and Search
004: * http://sourceforge.net/projects/lius/
005: *
006: * Copyright (c) 2005, Laval University Library. All rights reserved.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
021: */
022:
023: package ca.ulaval.bibl.lius.ThreadAction;
024:
025: import java.io.IOException;
026:
027: import org.apache.log4j.Logger;
028: import org.apache.lucene.index.Term;
029:
030: import ca.ulaval.bibl.lius.Exception.LiusException;
031: import ca.ulaval.bibl.lius.Lucene.LuceneActions;
032:
033: /**
034: *
035: * Classe utilisant des threads pour mettre à jour des documents dans l'index.
036: *
037: * <br/><br/>
038: *
039: * Class using threads for updating documents in index.
040: *
041: *
042: *
043: * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
044: *
045: */
046:
047: public class ThreadIndexUpdating
048:
049: extends Thread {
050:
051: static Logger logger = Logger.getRootLogger();
052:
053: private String dir = "";
054:
055: private String field = "";
056:
057: private String content = "";
058:
059: private String fileToIndex = "";
060:
061: private String config = "";
062:
063: private Term term = null;
064:
065: private boolean populated = false;
066:
067: private boolean populatedWithTerm = false;
068:
069: public ThreadIndexUpdating(String dir, String field,
070: String content,
071:
072: String fileToIndex, String config) {
073:
074: this .dir = dir;
075:
076: this .field = field;
077:
078: this .content = content;
079:
080: this .fileToIndex = fileToIndex;
081:
082: this .config = config;
083:
084: populated = true;
085:
086: }
087:
088: public ThreadIndexUpdating(String dir, Term term,
089: String fileToIndex,
090:
091: String config) {
092:
093: this .dir = dir;
094:
095: this .term = term;
096:
097: this .fileToIndex = fileToIndex;
098:
099: this .config = config;
100:
101: boolean populatedWithTerm = true;
102:
103: }
104:
105: public void run() {
106:
107: if (populated == true) {
108:
109: try {
110:
111: LuceneActions.getSingletonInstance().updateDoc(dir,
112: field, content,
113:
114: fileToIndex, config);
115:
116: try {
117:
118: Thread.sleep(1000);
119:
120: }
121:
122: catch (InterruptedException ex) {
123:
124: logger.error(ex.getMessage());
125:
126: }
127:
128: }
129:
130: catch (LiusException e) {
131:
132: logger.error(e.getMessage());
133:
134: }
135:
136: catch (IOException e) {
137:
138: logger.error(e.getMessage());
139:
140: }
141:
142: }
143:
144: else if (populatedWithTerm == true) {
145:
146: try {
147:
148: LuceneActions.getSingletonInstance().updateDoc(dir,
149: term, fileToIndex,
150:
151: config);
152:
153: try {
154:
155: Thread.sleep(1000);
156:
157: }
158:
159: catch (InterruptedException ex) {
160:
161: logger.error(ex.getMessage());
162:
163: }
164:
165: }
166:
167: catch (LiusException e) {
168:
169: logger.error(e.getMessage());
170:
171: }
172:
173: catch (IOException e) {
174:
175: logger.error(e.getMessage());
176:
177: }
178:
179: }
180:
181: }
182:
183: }
|