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 org.apache.log4j.Logger;
026: import org.apache.lucene.index.Term;
027:
028: import ca.ulaval.bibl.lius.Exception.LiusException;
029: import ca.ulaval.bibl.lius.Lucene.LuceneActions;
030:
031: /**
032: *
033: * Classe utilisant des Threads pour supprimer des documents de l'index.
034: *
035: * <br/><br/>
036: *
037: * Class using threads to delete documents from index.
038: *
039: *
040: *
041: * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
042: *
043: */
044:
045: public class ThreadDeleteDoc
046:
047: extends Thread {
048:
049: static Logger logger = Logger.getRootLogger();
050:
051: private String dir = "";
052:
053: private String field = "";
054:
055: private String content = "";
056:
057: private Term term = null;
058:
059: private boolean populated = false;
060:
061: private boolean populatedWithTerm = false;
062:
063: public ThreadDeleteDoc(String dir, String field, String content) {
064:
065: this .dir = dir;
066:
067: this .field = field;
068:
069: this .content = content;
070:
071: populated = true;
072:
073: }
074:
075: public ThreadDeleteDoc(String dir, Term term) {
076:
077: this .dir = dir;
078:
079: this .term = term;
080:
081: boolean populatedWithTerm = true;
082:
083: }
084:
085: public void run() {
086:
087: if (populated == true) {
088:
089: try {
090:
091: LuceneActions.getSingletonInstance().deleteDoc(dir,
092: field, content);
093:
094: try {
095:
096: Thread.sleep(1000);
097:
098: }
099:
100: catch (InterruptedException ex) {
101:
102: logger.error(ex.getMessage());
103:
104: }
105:
106: }
107:
108: catch (LiusException e) {
109:
110: logger.error(e.getMessage());
111:
112: }
113:
114: }
115:
116: else if (populatedWithTerm == true) {
117:
118: try {
119:
120: LuceneActions.getSingletonInstance().deleteDoc(dir,
121: term);
122:
123: }
124:
125: catch (LiusException e) {
126:
127: logger.error(e.getMessage());
128:
129: }
130:
131: }
132:
133: }
134:
135: }
|