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.main.samples;
024:
025: import java.io.File;
026: import java.io.IOException;
027: import java.util.List;
028: import java.util.StringTokenizer;
029:
030: import org.apache.lucene.analysis.Analyzer;
031: import org.apache.lucene.index.IndexWriter;
032:
033: import ca.ulaval.bibl.lius.LiusLogger;
034: import ca.ulaval.bibl.lius.Exception.LiusException;
035: import ca.ulaval.bibl.lius.Lucene.AnalyzerFactory;
036: import ca.ulaval.bibl.lius.Lucene.LuceneActions;
037: import ca.ulaval.bibl.lius.config.LiusConfig;
038: import ca.ulaval.bibl.lius.config.LiusConfigBuilder;
039: import ca.ulaval.bibl.lius.index.XML.XmlNodeIndexer;
040:
041: /**
042: *
043: * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
044: *
045: */
046:
047: public class IndexingXmlNodes {
048:
049: public static void main(String[] args) throws IOException {
050:
051: String sep = File.separator;
052:
053: StringTokenizer st = new StringTokenizer(System.getProperty(
054:
055: "java.class.path"), File.pathSeparator);
056:
057: File classDir = new File(st.nextToken());
058:
059: String indexDir = classDir.getParent() + sep + "luceneIndex";
060:
061: String liusConfig = classDir.getParent() + sep + "Config" + sep
062: +
063:
064: "liusXmlNodesConfig.xml";
065:
066: String log4j = classDir.getParent() + sep + "Config" + sep
067: + "log4j" + sep + "log4j.properties";
068:
069: //test 1
070:
071: String toIndex = classDir.getParent() + sep + "ExempleFiles"
072: + sep +
073:
074: "node.xml";
075:
076: LiusLogger.setLoggerConfigFile(log4j);
077:
078: LiusConfig lc = LiusConfigBuilder.getSingletonInstance().
079:
080: getLiusConfig(liusConfig);
081:
082: Analyzer analyzer = AnalyzerFactory.getAnalyzer(lc);
083:
084: IndexWriter writer = null;
085:
086: try {
087:
088: LuceneActions.getSingletonInstance().deleteAllDocuments(
089: indexDir);
090:
091: boolean createIndex = LuceneActions.getSingletonInstance().
092:
093: createIndexValue(lc.getCreateIndex(), indexDir);
094:
095: writer = new IndexWriter(indexDir, analyzer, createIndex);
096:
097: XmlNodeIndexer nodeIndexer = new XmlNodeIndexer();
098:
099: List lucenedocsListe = nodeIndexer
100: .createLuceneDocForEachNodeOfDocument(
101:
102: toIndex, lc.getXmlNodesFields());
103:
104: LuceneActions.getSingletonInstance().save(lucenedocsListe,
105: writer, lc);
106:
107: }
108:
109: catch (IOException e) {
110:
111: e.printStackTrace();
112:
113: }
114:
115: catch (LiusException e) {
116:
117: e.printStackTrace();
118:
119: }
120:
121: finally {
122:
123: writer.close();
124:
125: LuceneActions.getSingletonInstance().unLock(indexDir);
126:
127: }
128:
129: }
130:
131: }
|