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.ArrayList;
028: import java.util.List;
029: import java.util.StringTokenizer;
030:
031: import ca.ulaval.bibl.lius.LiusLogger;
032: import ca.ulaval.bibl.lius.Lucene.LuceneActions;
033: import ca.ulaval.bibl.lius.main.beans.Book;
034: import ca.ulaval.bibl.lius.main.beans.Personne;
035:
036: /**
037: *
038: * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
039: *
040: */
041:
042: public class IndexingJavaBeans {
043:
044: public IndexingJavaBeans() {
045:
046: }
047:
048: public static void main(String[] args) {
049:
050: String sep = File.separator;
051:
052: StringTokenizer st = new StringTokenizer(System.getProperty(
053:
054: "java.class.path"), File.pathSeparator);
055:
056: File classDir = new File(st.nextToken());
057:
058: String indexDir = classDir.getParent() + sep + "luceneIndex";
059:
060: String liusConfig = classDir.getParent() + sep + "Config" + sep
061: +
062:
063: "liusBeansConfig.xml";
064:
065: String log4j = classDir.getParent() + sep + "Config" + sep
066: + "log4j" + sep + "log4j.properties";
067:
068: //Liste des beans à indexer
069:
070: List beans = new ArrayList();
071:
072: //Bean Book
073:
074: Book b = new Book();
075:
076: b.setTitle("Lucene index update and search");
077:
078: b.setCreator("Rida Benjelloun");
079:
080: beans.add(b);
081:
082: //Bean Personne
083:
084: Personne p = new Personne();
085:
086: p.setNom("Benjelloun");
087:
088: p.setPrenom("Miya");
089:
090: p.setAdresse("3061 des chatelets");
091:
092: beans.add(p);
093:
094: // Indexation
095:
096: System.out.println("@@@@@@ Indexation : ");
097:
098: try {
099:
100: LiusLogger.setLoggerConfigFile(log4j);
101:
102: LuceneActions.getSingletonInstance().deleteAllDocuments(
103: indexDir);
104:
105: LuceneActions.getSingletonInstance().indexJavaBeans(beans,
106: indexDir,
107:
108: liusConfig);
109:
110: }
111:
112: catch (IOException ex) {
113:
114: ex.printStackTrace();
115:
116: }
117:
118: }
119:
120: }
|