/* * GS2LuceneSearch.java * Copyright (C) 2006 New Zealand Digital Library, http://www.nzdl.org * * This program is free software; you can redistribute it and/or modify * 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.NodeList; import org.w3c.dom.Document; // java classes import java.util.ArrayList; import java.util.HashMap; import java.io.File; import java.util.Iterator; import java.util.Set; import java.util.Map; import java.util.Vector; // Logging import org.apache.log4j.Logger; import org.greenstone.LuceneWrapper.GS2LuceneQuery; import org.greenstone.LuceneWrapper.LuceneQueryResult; public class GS2LuceneSearch extends AbstractGS2FieldSearch { protected static final String RANK_PARAM_RANK_VALUE = "rank"; static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2LuceneSearch.class.getName()); private GS2LuceneQuery lucene_src=null; public GS2LuceneSearch() { this.lucene_src = new GS2LuceneQuery(); // Lucene uses double operators, not single AND_OPERATOR = "&&"; OR_OPERATOR = "||"; does_paging = true; does_chunking = true; } public void cleanUp() { super.cleanUp(); this.lucene_src.cleanUp(); } /** configure this service */ public boolean configure(Element info, Element extra_info) { if (!super.configure(info, extra_info)){ return false; } // Lucene doesn't do case folding or stemming or accent folding at the // moment does_case = false; does_stem = false; does_accent = false; return true; } /** add in the lucene specific params to TextQuery */ protected void addCustomQueryParams(Element param_list, String lang) { super.addCustomQueryParams(param_list, lang); /** lucenes rank param is based on index fields, not ranked/not */ createParameter(RANK_PARAM, param_list, lang); } /** create a param and add to the list */ /** we override this to do a special rank param */ protected void createParameter(String name, Element param_list, String lang) { Element param = null; if (name.equals(RANK_PARAM)) { // get the fields ArrayList fields = new ArrayList(); fields.add(RANK_PARAM_RANK_VALUE); ArrayList field_names = new ArrayList(); field_names.add(getTextString("param.sortBy.rank", lang)); getSortByIndexData(fields, field_names, lang); param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names ); } if (param != null) { param_list.appendChild(param); } else { super.createParameter(name, param_list, lang); } } protected void getSortByIndexData(ArrayList index_ids, ArrayList index_names, String lang) { // the index info - Element index_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_ELEM+GSXML.LIST_MODIFIER); NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM); int len = indexes.getLength(); // now add even if there is only one for (int i=0; i0) { combine = " "+c+" "; } s.append(combine + addFieldInfo(q,f)); } /** Lucene doesn't use these options at the moment */ protected String addStemOptions(String query, String stem, String casef, String accent) { return query; } }