/* * MapSearch.java * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.greenstone.gsdl3.service; // Greenstone classes import org.greenstone.gsdl3.util.*; // XML classes import org.w3c.dom.Element; import org.w3c.dom.Document; import org.w3c.dom.NodeList; // General java classes import java.util.Hashtable; import java.util.HashMap; import java.util.Arrays; import java.util.ArrayList; import java.util.LinkedList; import java.lang.reflect.Array; import java.util.Comparator; import java.io.BufferedReader; import java.io.FileReader; import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.FileInputStream; import java.lang.ClassNotFoundException; import org.apache.log4j.*; /** * * */ public class MapSearch extends AbstractSearch { static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.MapSearch.class.getName()); protected String files_home_dir = null; protected static final String FREQ_ATT = "freq"; // use the following if we add back in index searching //protected String default_index = null; //protected static final String DEFAULT_INDEX_ELEM = "defaultIndex"; //protected static final String INDEX_ELEM = "index"; /** Hashtable containing the place names database, indexed on the place name in lower case. */ public static Hashtable hashNames; /** Constructor */ public MapSearch() {} /** */ public boolean configure(Element info, Element extra_info) { if (!super.configure(info, extra_info)) { return false; } logger.info("Configuring MapSearch..."); // set the files_home_dir variable for this collection this.files_home_dir = GSFile.collectionIndexDir(site_home, cluster_name)+File.separator+"assoc"+File.separator; //load the hashtable hashNames = new Hashtable(); try{ ObjectInputStream in = new ObjectInputStream(new FileInputStream(this.files_home_dir+"hashnames.dat")); hashNames = (Hashtable)in.readObject(); in.close(); }catch(IOException ioe){ ioe.printStackTrace(); return false; }catch(ClassNotFoundException cnf){ cnf.printStackTrace(); return false; } // just in case we get the index stuff going, here is the code // get the display stuff for the indexes // NodeList indexes = info.getElementsByTagName(GSXML.INDEX_ELEM); // if (extra_info != null) { // Document owner = info.getOwnerDocument(); // Element config_search = (Element)GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM); // if (config_search != null) { // for (int i=0; i (buildConfig.xml) // Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM); // if (def != null) { // default_index = def.getAttribute(GSXML.NAME_ATT); // } // if (default_index == null || default_index.equals("")) { // // use the first one from the index list // default_index = ((Element)indexes.item(0)).getAttribute(GSXML.NAME_ATT); // } return true; } protected void getIndexData(ArrayList index_ids, ArrayList index_names, String lang) { // for now, we just have one dummy index index_ids.add("idx"); index_names.add("maps"); // get from properties // use the following if we ever get the index search working // Element index_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_ELEM+GSXML.LIST_MODIFIER); // NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM); // for (int i=0; i= xtop && xco < xbot && yco >= ytop && yco < ybot) mapList.add(readString+"```"+nameData); } }catch(Exception e){e.printStackTrace();} } } // use an array object to sort the linked list by map number Object[] mapListArray = mapList.toArray(); Arrays.sort(mapListArray); mapList.clear(); for(int mla=0; mla0){ readString = (String)mapList.removeFirst(); if(mapNumber.equals(readString.substring(0,readString.indexOf('.')))){ currentMap[1] = currentMap[1]+readString.substring(readString.indexOf("```"),readString.length()); mapFreq++; } else{ if(!currentMap[0].equals("")) tempList.add(currentMap[0]+"`"+mapFreq+currentMap[1]); currentMap[0] = readString.substring(0,readString.indexOf("```")); currentMap[1] = readString.substring(readString.indexOf("```"),readString.length()); mapNumber = readString.substring(0,readString.indexOf('.')); mapFreq=1; } } if(!currentMap[0].equals("")) tempList.add(currentMap[0]+"`"+mapFreq+currentMap[1]); int totalDocs = tempList.size(); // use an array object to sort the linked list by number of matches on each map Object[] tempListArray = tempList.toArray(); Arrays.sort(tempListArray, new MapResultSorter()); tempList.clear(); for(int tla=0; tla secondInt) return -1; else if(firstInt == secondInt) return 0; else return 1; } } }