Changeset 25853


Ignore:
Timestamp:
2012-06-28T11:24:00+12:00 (12 years ago)
Author:
sjm84
Message:

Reformatting and tidying the imports of this file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java

    r25726 r25853  
    11/*
    2 *    SharedSoleneGS2FieldSearch.java -- shared base code for Solr and Lucene
    3 *    Copyright (C) 2006 New Zealand Digital Library, http://www.nzdl.org
    4 *
    5 *    This program is free software; you can redistribute it and/or modify
    6 *   the Free Software Foundation; either version 2 of the License, or
    7 *    (at your option) any later version.
    8 *
    9 *    This program is distributed in the hope that it will be useful,
    10 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 *    GNU General Public License for more details.
    13 *
    14 *    You should have received a copy of the GNU General Public License
    15 *    along with this program; if not, write to the Free Software
    16 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17 */
     2 *    SharedSoleneGS2FieldSearch.java -- shared base code for Solr and Lucene
     3 *    Copyright (C) 2006 New Zealand Digital Library, http://www.nzdl.org
     4 *
     5 *    This program is free software; you can redistribute it and/or modify
     6 *   the Free Software Foundation; either version 2 of the License, or
     7 *    (at your option) any later version.
     8 *
     9 *    This program is distributed in the hope that it will be useful,
     10 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 *    GNU General Public License for more details.
     13 *
     14 *    You should have received a copy of the GNU General Public License
     15 *    along with this program; if not, write to the Free Software
     16 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17 */
    1818
    1919package org.greenstone.gsdl3.service;
    2020
    2121// Greenstone classes
    22 import org.greenstone.gsdl3.util.*;
     22import java.util.ArrayList;
    2323
    24 // XML classes
    25 import org.w3c.dom.Element;
     24import org.apache.log4j.Logger;
     25import org.greenstone.LuceneWrapper3.SharedSoleneQuery;
     26import org.greenstone.gsdl3.util.GSXML;
     27import org.w3c.dom.Element;
    2628import org.w3c.dom.NodeList;
    27 import org.w3c.dom.Document;
    28 // java classes
    29 import java.util.ArrayList;
    30 import java.util.HashMap;
    31 import java.io.File;
    32 import java.util.Iterator;
    33 import java.util.Set;
    34 import java.util.Map;
    35 import java.util.Vector;
    36 
    37 // Logging
    38 import org.apache.log4j.Logger;
    39 
    40 import org.greenstone.LuceneWrapper3.SharedSoleneQueryResult;
    41 import org.greenstone.LuceneWrapper3.SharedSoleneQuery;
    4229
    4330// Shared code for Solr and Lucene GS2FieldSearch
     
    4532public abstract class SharedSoleneGS2FieldSearch extends AbstractGS2FieldSearch
    4633{
    47     protected static final String RANK_PARAM_RANK_VALUE = "rank";
     34    protected static final String RANK_PARAM_RANK_VALUE = "rank";
    4835
    49     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SharedSoleneGS2FieldSearch.class.getName());
     36    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SharedSoleneGS2FieldSearch.class.getName());
    5037
    51     protected SharedSoleneQuery solene_src=null;   
     38    protected SharedSoleneQuery solene_src = null;
    5239
    53     public SharedSoleneGS2FieldSearch()
    54     {
    55     // Lucene/Solr uses double operators, not single
    56     AND_OPERATOR = "&&";
    57     OR_OPERATOR = "||";
     40    public SharedSoleneGS2FieldSearch()
     41    {
     42        // Lucene/Solr uses double operators, not single
     43        AND_OPERATOR = "&&";
     44        OR_OPERATOR = "||";
    5845
    59     does_paging = true;
    60     does_chunking = true;
    61     }
    62    
    63    
    64     /** configure this service */
    65     public boolean configure(Element info, Element extra_info)
    66     {
    67     if (!super.configure(info, extra_info)){
    68         return false;
     46        does_paging = true;
     47        does_chunking = true;
    6948    }
    70        
    71     // Lucene/Solr doesn't do case folding or stemming or accent folding at the
    72     // moment
    73     does_case = false;
    74     does_stem = false;
    75     does_accent = false;
    7649
    77     return true;
    78     }
    79    
    80     /** add in the Lucene/Solr specific params to TextQuery */
    81     protected void addCustomQueryParams(Element param_list, String lang)
    82     {
    83     super.addCustomQueryParams(param_list, lang);
    84     /** Lucene's/Solr's rank param is based on index fields, not ranked/not */
    85     createParameter(RANK_PARAM, param_list, lang);
    86     }
    87    
    88     /** create a param and add to the list */
    89     /** we override this to do a special rank param */
    90     protected void createParameter(String name, Element param_list, String lang)
    91     {
     50    /** configure this service */
     51    public boolean configure(Element info, Element extra_info)
     52    {
     53        if (!super.configure(info, extra_info))
     54        {
     55            return false;
     56        }
     57
     58        // Lucene/Solr doesn't do case folding or stemming or accent folding at the
     59        // moment
     60        does_case = false;
     61        does_stem = false;
     62        does_accent = false;
     63
     64        return true;
     65    }
     66
     67    /** add in the Lucene/Solr specific params to TextQuery */
     68    protected void addCustomQueryParams(Element param_list, String lang)
     69    {
     70        super.addCustomQueryParams(param_list, lang);
     71        /** Lucene's/Solr's rank param is based on index fields, not ranked/not */
     72        createParameter(RANK_PARAM, param_list, lang);
     73    }
     74
     75    /** create a param and add to the list */
     76    /** we override this to do a special rank param */
     77    protected void createParameter(String name, Element param_list, String lang)
     78    {
    9279        Element param = null;
    93         if (name.equals(RANK_PARAM)) {
     80        if (name.equals(RANK_PARAM))
     81        {
    9482            // get the fields
    9583            ArrayList<String> fields = new ArrayList<String>();
    9684            fields.add(RANK_PARAM_RANK_VALUE);
    9785            ArrayList<String> field_names = new ArrayList<String>();
    98             field_names.add(getTextString("param.sortBy.rank", lang)); 
     86            field_names.add(getTextString("param.sortBy.rank", lang));
    9987            getSortByIndexData(fields, field_names, lang);
    100            
    101             param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names );
     88
     89            param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
    10290        }
    103         if (param != null) {
     91        if (param != null)
     92        {
    10493            param_list.appendChild(param);
    105         } else {
     94        }
     95        else
     96        {
    10697            super.createParameter(name, param_list, lang);
    10798        }
    10899    }
    109    
    110     protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang) {
     100
     101    protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang)
     102    {
    111103        // the index info -
    112         Element index_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_ELEM+GSXML.LIST_MODIFIER);
     104        Element index_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_ELEM + GSXML.LIST_MODIFIER);
    113105        NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM);
    114106        int len = indexes.getLength();
    115107        // now add even if there is only one
    116         for (int i=0; i<len; i++) {
    117             Element index = (Element)indexes.item(i);
     108        for (int i = 0; i < len; i++)
     109        {
     110            Element index = (Element) indexes.item(i);
    118111            String shortname = index.getAttribute(GSXML.SHORTNAME_ATT);
    119             if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX")) {
     112            if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX"))
     113            {
    120114                continue;
    121115            }
    122             index_ids.add("by"+shortname);
     116            index_ids.add("by" + shortname);
    123117            String display_name = GSXML.getDisplayText(index, GSXML.DISPLAY_TEXT_NAME, lang, "en");
    124             if (display_name.equals("")) {
     118            if (display_name.equals(""))
     119            {
    125120                display_name = index.getAttribute(GSXML.NAME_ATT);
    126                 if (display_name.equals("")) {
     121                if (display_name.equals(""))
     122                {
    127123                    display_name = shortname;
    128124                }
    129125            }
    130126            index_names.add(display_name);
    131            
     127
    132128        }
    133        
     129
    134130    }
    135131
    136     protected String addFieldInfo(String query, String field) {
    137       // currently, allfields (ZZ) is stored as a extra field for Lucene
    138       if (field.equals("")) { // || field.equals("ZZ")) {
    139         return query;
     132    protected String addFieldInfo(String query, String field)
     133    {
     134        // currently, allfields (ZZ) is stored as a extra field for Lucene
     135        if (field.equals(""))
     136        { // || field.equals("ZZ")) {
     137            return query;
     138        }
     139        return field + ":(" + query + ")";
    140140    }
    141     return field+":("+query+")";
    142     }
    143    
    144     protected void addQueryElem(StringBuffer s, String q, String f, String c) {
    145    
    146     String combine="";
    147     if (s.length()>0) {
    148         combine = " "+c+" ";
     141
     142    protected void addQueryElem(StringBuffer s, String q, String f, String c)
     143    {
     144
     145        String combine = "";
     146        if (s.length() > 0)
     147        {
     148            combine = " " + c + " ";
     149        }
     150        s.append(combine + addFieldInfo(q, f));
    149151    }
    150     s.append(combine + addFieldInfo(q,f));
    151     }
    152    
    153     /** Lucene/Solr doesn't use these options at the moment */
    154     protected String addStemOptions(String query, String stem,
    155                     String casef, String accent)
    156     {
    157     return query;
    158     }
    159152
    160     /** Lucene/Solr does not use internal ids. It just uses hash ids. So we need
    161     to override these methods so no conversion is done. */
    162     /** convert indexer internal id to Greenstone oid */
    163     protected String internalNum2OID(long docnum)
    164     {
    165     return Long.toString(docnum);   
    166     }
     153    /** Lucene/Solr doesn't use these options at the moment */
     154    protected String addStemOptions(String query, String stem, String casef, String accent)
     155    {
     156        return query;
     157    }
    167158
    168     protected String internalNum2OID(String docnum)
    169     {
    170     return docnum;
    171    
    172     }
     159    /**
     160     * Lucene/Solr does not use internal ids. It just uses hash ids. So we need
     161     * to override these methods so no conversion is done.
     162     */
     163    /** convert indexer internal id to Greenstone oid */
     164    protected String internalNum2OID(long docnum)
     165    {
     166        return Long.toString(docnum);
     167    }
     168
     169    protected String internalNum2OID(String docnum)
     170    {
     171        return docnum;
     172
     173    }
    173174}
Note: See TracChangeset for help on using the changeset viewer.