/*
* LIUS - Lucene Index Update and Search
* http://sourceforge.net/projects/lius/
*
* Copyright (c) 2005, Laval University Library. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package lius.main;
/**
*
* @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
*
*/
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.IOException;
// import java.util.ArrayList;
import java.io.File;
import java.util.StringTokenizer;
import lius.Lucene.LuceneActions;
import lius.config.LiusConfig;
import lius.config.LiusConfigBuilder;
import lius.config.LiusField;
import lius.search.LiusHit;
import lius.search.SearchIndex;
import lius.search.sort.SortResults;
import lius.util.LiusUtils;
// import org.jdom.Document;
public class TestUtils {
public static void main(String[] args) throws IOException {
SearchIndex si = new SearchIndex();
String sep = File.separator;
StringTokenizer st = new StringTokenizer(System.getProperty(
"java.class.path"), File.pathSeparator);
File classDir = new File(st.nextToken());
String indexDir = classDir.getParent() + sep + "index";
String indexDir1 = classDir.getParent() + sep + "luceneIndex1";
String liusConfig = classDir.getParent() + sep + "Config" + sep +
"liusConfig.xml";
/*
* List res = si.search("la*", indexDir, liusConfig);
*
* LiusUtils.printResults(res);
*
* LiusConfig lc =
* LiusConfigBuilder.getSingletonInstance().getLiusConfig( liusConfig);
* /* List indexs = new ArrayList();
*
* indexs.add(indexDir);
*
* indexs.add(indexDir1);
*
* Document jdomDocument =
* si.multiIndexSearchResultsAsJDom("gouv*",indexs,liusConfig);
*
* LiusUtils.saveInXmlFile(jdomDocument,"c:\\test2.xml");
*
*/
/*
* Document jdomDocument =
* si.searchResultAsJdomDoc("ca*",indexDir,liusConfig);
*
* LiusUtils.saveInXmlFile(jdomDocument,"c:\\test2.xml");
*/
/*
* List res = si.search("un",indexDir,liusConfig);
*
* LiusUtils.printResults(res);
*/
/*
* List indexs = new ArrayList();
*
* indexs.add(indexDir);
*
* indexs.add(indexDir1);
*
*
*
* List res = si.multiIndexSearch("xml", indexs, liusConfig);
*
* LiusUtils.printResults(res);
*/
LiusConfig lc = LiusConfigBuilder.getSingletonInstance().getLiusConfig(
liusConfig);
//Browsing
List bi1 = LuceneActions.getSingletonInstance().ListAllDocuments(
indexDir, lc);
List bi = SortResults.sortBy(bi1,"Ident");
for (int i = 0; i < bi.size(); i++) {
LiusHit lh = (LiusHit) bi.get(i);
System.out.println("=========" + lh.getDocId());
Map fields = lh.getLiusFieldsMap();
Set s = fields.keySet();
Iterator it = s.iterator();
while (it.hasNext()) {
String key = (String) it.next();
System.out.println(key + ": "
+ ((LiusField) fields.get(key)).getValue());
}
}
//Map Search
/*List bi1 = si.searchAsLiusHitMap("camelot", indexDir, liusConfig);
List bi = SortResults.sortBy(bi1,"Ident");
for (int i = 0; i < bi.size(); i++) {
LiusHit lh = (LiusHit) bi.get(i);
System.out.println("=========" + lh.getDocId());
System.out.println("score : " + lh.getScore());
Map fields = lh.getLiusFieldsMap();
Set s = fields.keySet();
Iterator it = s.iterator();
while (it.hasNext()) {
String key = (String) it.next();
System.out.print(key + ": ");
String[] values = ((LiusField) fields.get(key)).getValuesTab();
for(int r=0; r < values.length; r++)
System.out.println(values[r]);
}
}*/
}
}