Changeset 25765


Ignore:
Timestamp:
2012-06-06T14:31:43+12:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file and cleaning up imports

File:
1 edited

Legend:

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

    r25727 r25765  
    2020
    2121// Greenstone classes
     22import java.util.ArrayList;
     23
     24import org.apache.log4j.Logger;
    2225import org.greenstone.gsdl3.util.GSXML;
    23 import org.greenstone.gsdl3.util.GSPath;
     26import org.w3c.dom.Element;
    2427
    25 // XML classes
    26 import org.w3c.dom.Document;
    27 import org.w3c.dom.Element;
    28 import org.w3c.dom.NodeList;
    29 
    30 // java classes
    31 import java.util.ArrayList;
    32 import java.util.HashMap;
    33 
    34 import org.apache.log4j.*;
    35 
    36 /** Partially implements a generic search service
    37  *
     28/**
     29 * Partially implements a generic search service
     30 *
    3831 */
    3932
    40 public abstract class AbstractTextSearch
    41     extends AbstractSearch
     33public abstract class AbstractTextSearch extends AbstractSearch
    4234{
    4335
    44    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractTextSearch.class.getName());
     36    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractTextSearch.class.getName());
    4537
    46    
    47     // optional standard params - some of these have to be implemented
    48     protected static final String INDEX_SUBCOLLECTION_PARAM = "indexSubcollection";
    49     protected static final String INDEX_LANGUAGE_PARAM = "indexLanguage";
     38    // optional standard params - some of these have to be implemented
     39    protected static final String INDEX_SUBCOLLECTION_PARAM = "indexSubcollection";
     40    protected static final String INDEX_LANGUAGE_PARAM = "indexLanguage";
    5041
    51     protected static final String INDEX_SUBCOLLECTION_ELEM = "indexSubcollection";
    52     protected static final String INDEX_LANGUAGE_ELEM = "indexLanguage";
    53    
     42    protected static final String INDEX_SUBCOLLECTION_ELEM = "indexSubcollection";
     43    protected static final String INDEX_LANGUAGE_ELEM = "indexLanguage";
    5444
    55     // some other common params that may be used
    56     protected static final String CASE_PARAM = "case";
    57     protected static final String STEM_PARAM = "stem";
    58     protected static final String ACCENT_PARAM="accent";
     45    // some other common params that may be used
     46    protected static final String CASE_PARAM = "case";
     47    protected static final String STEM_PARAM = "stem";
     48    protected static final String ACCENT_PARAM = "accent";
    5949
    60     protected static final String BOOLEAN_PARAM_ON = "1";
    61     protected static final String BOOLEAN_PARAM_OFF = "0";
    62     protected static final String MATCH_PARAM = "matchMode";
    63     protected static final String MATCH_PARAM_ALL = "all";
    64     protected static final String MATCH_PARAM_SOME = "some";
     50    protected static final String BOOLEAN_PARAM_ON = "1";
     51    protected static final String BOOLEAN_PARAM_OFF = "0";
     52    protected static final String MATCH_PARAM = "matchMode";
     53    protected static final String MATCH_PARAM_ALL = "all";
     54    protected static final String MATCH_PARAM_SOME = "some";
    6555
    66     protected String default_index_subcollection = "";
     56    protected String default_index_subcollection = "";
    6757
    68     protected String default_index_language = "";
    69    
    70     public AbstractTextSearch()
    71     {
    72     // the search service
    73     QUERY_SERVICE = "TextQuery";
    74     }
     58    protected String default_index_language = "";
    7559
    76 
    77     /** adds the standard query params into the service description */
    78     protected void addStandardQueryParams(Element param_list, String lang)
    79     {
    80     if (!default_index_subcollection.equals("")){
    81         createParameter(INDEX_SUBCOLLECTION_PARAM,param_list, lang);
    82     }
    83     if (!default_index_language.equals("")){
    84         createParameter(INDEX_LANGUAGE_PARAM,param_list, lang);
     60    public AbstractTextSearch()
     61    {
     62        // the search service
     63        QUERY_SERVICE = "TextQuery";
    8564    }
    8665
    87     super.addStandardQueryParams(param_list,lang);
    88     }
     66    /** adds the standard query params into the service description */
     67    protected void addStandardQueryParams(Element param_list, String lang)
     68    {
     69        if (!default_index_subcollection.equals(""))
     70        {
     71            createParameter(INDEX_SUBCOLLECTION_PARAM, param_list, lang);
     72        }
     73        if (!default_index_language.equals(""))
     74        {
     75            createParameter(INDEX_LANGUAGE_PARAM, param_list, lang);
     76        }
    8977
    90     /** Top up createParameterChain with TextQuery specific params:
    91      *    case, stem ...
    92      */
    93      protected boolean createParameterChain(String name, Element param_list, String lang, String default_value)
    94     {
    95     Element param = null;
    96     String param_default = default_value;
    97 
    98     if (super.createParameterChain(name,param_list,lang,default_value)) {
    99         // found a match, so can stop here
    100         return true;
    101     }
    102     // otherwise look to see if it is a text specific parameter
    103     else if (name.equals(INDEX_SUBCOLLECTION_PARAM)){
    104         Element index_sub_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_SUBCOLLECTION_ELEM+GSXML.LIST_MODIFIER);
    105         if (index_sub_list == null) return true; // processed, just not a very interesting result
    106         ArrayList<String> index_sub_ids = new ArrayList<String>();
    107         ArrayList<String> index_sub_names = new ArrayList<String>();
    108         getIndexSubcollectionData(index_sub_ids, index_sub_names, lang);
    109         String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
    110         if (does_multi_index_search) {
    111         param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
    112         }
    113         if (param_default == null) {
    114           param_default = this.default_index_subcollection;
    115         }
    116         param = GSXML.createParameterDescription2(this.doc, INDEX_SUBCOLLECTION_PARAM, getTextString("param."+INDEX_SUBCOLLECTION_PARAM, lang), param_type, param_default, index_sub_ids, index_sub_names);
    117         param_list.appendChild(param);
    118         return true;
    119     }
    120     else if(name.equals(INDEX_LANGUAGE_PARAM)){
    121         Element index_lang_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_LANGUAGE_ELEM+GSXML.LIST_MODIFIER);
    122             if (index_lang_list == null) return true; // processed, just not a very interesting result
    123         ArrayList<String> index_lang_ids = new ArrayList<String>();
    124         ArrayList<String> index_lang_names = new ArrayList<String>();
    125         getIndexLanguageData(index_lang_ids, index_lang_names, lang);
    126         String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
    127         if (does_multi_index_search) {
    128         param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
    129         }
    130         if (param_default == null) {
    131           param_default = this.default_index_language;
    132         }
    133         param = GSXML.createParameterDescription2(this.doc, INDEX_LANGUAGE_PARAM, getTextString("param."+INDEX_LANGUAGE_PARAM, lang), param_type, param_default, index_lang_ids, index_lang_names);
    134         param_list.appendChild(param);
    135         return true;
     78        super.addStandardQueryParams(param_list, lang);
    13679    }
    13780
    138     // Get to there then none of the above params matched
    139     // => return false so the chain can continue
    140     return false;
    141        
    142     }
     81    /**
     82     * Top up createParameterChain with TextQuery specific params: case, stem
     83     * ...
     84     */
     85    protected boolean createParameterChain(String name, Element param_list, String lang, String default_value)
     86    {
     87        Element param = null;
     88        String param_default = default_value;
    14389
    144     /** do the actual query
    145      * must be implemented by subclass */
    146     abstract protected Element processTextQuery(Element request);
    147    
    148     /** get the details about the indexexSubcollections available
    149      * might be implemented by subclass
    150      */
    151     protected void getIndexSubcollectionData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang){}
    152    
    153     /** get the details about the indexes available
    154      * might be implemented by subclass
    155      */
    156     protected void getIndexLanguageData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang){}
    157  
     90        if (super.createParameterChain(name, param_list, lang, default_value))
     91        {
     92            // found a match, so can stop here
     93            return true;
     94        }
     95        // otherwise look to see if it is a text specific parameter
     96        else if (name.equals(INDEX_SUBCOLLECTION_PARAM))
     97        {
     98            Element index_sub_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_SUBCOLLECTION_ELEM + GSXML.LIST_MODIFIER);
     99            if (index_sub_list == null)
     100                return true; // processed, just not a very interesting result
     101            ArrayList<String> index_sub_ids = new ArrayList<String>();
     102            ArrayList<String> index_sub_names = new ArrayList<String>();
     103            getIndexSubcollectionData(index_sub_ids, index_sub_names, lang);
     104            String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
     105            if (does_multi_index_search)
     106            {
     107                param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
     108            }
     109            if (param_default == null)
     110            {
     111                param_default = this.default_index_subcollection;
     112            }
     113            param = GSXML.createParameterDescription2(this.doc, INDEX_SUBCOLLECTION_PARAM, getTextString("param." + INDEX_SUBCOLLECTION_PARAM, lang), param_type, param_default, index_sub_ids, index_sub_names);
     114            param_list.appendChild(param);
     115            return true;
     116        }
     117        else if (name.equals(INDEX_LANGUAGE_PARAM))
     118        {
     119            Element index_lang_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_LANGUAGE_ELEM + GSXML.LIST_MODIFIER);
     120            if (index_lang_list == null)
     121                return true; // processed, just not a very interesting result
     122            ArrayList<String> index_lang_ids = new ArrayList<String>();
     123            ArrayList<String> index_lang_names = new ArrayList<String>();
     124            getIndexLanguageData(index_lang_ids, index_lang_names, lang);
     125            String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
     126            if (does_multi_index_search)
     127            {
     128                param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
     129            }
     130            if (param_default == null)
     131            {
     132                param_default = this.default_index_language;
     133            }
     134            param = GSXML.createParameterDescription2(this.doc, INDEX_LANGUAGE_PARAM, getTextString("param." + INDEX_LANGUAGE_PARAM, lang), param_type, param_default, index_lang_ids, index_lang_names);
     135            param_list.appendChild(param);
     136            return true;
     137        }
     138
     139        // Get to there then none of the above params matched
     140        // => return false so the chain can continue
     141        return false;
     142
     143    }
     144
     145    /**
     146     * do the actual query must be implemented by subclass
     147     */
     148    abstract protected Element processTextQuery(Element request);
     149
     150    /**
     151     * get the details about the indexexSubcollections available might be
     152     * implemented by subclass
     153     */
     154    protected void getIndexSubcollectionData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang)
     155    {
     156    }
     157
     158    /**
     159     * get the details about the indexes available might be implemented by
     160     * subclass
     161     */
     162    protected void getIndexLanguageData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang)
     163    {
     164    }
    158165
    159166}
    160 
Note: See TracChangeset for help on using the changeset viewer.