Changeset 28181


Ignore:
Timestamp:
08/29/13 15:03:53 (7 years ago)
Author:
kjdon
Message:

making search param defaults able to be set in config file. uses <paramDefault name=xx value=yy> element. Now all defaults are set in paramDefaults HashMap instead of individual variables. have left index etc ones for now as they are more complicated.

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service
Files:
7 edited

Legend:

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

    r25893 r28181  
    9494    public AbstractGS2FieldSearch()
    9595    {
     96      super();
     97      paramDefaults.put(RANK_PARAM, RANK_PARAM_RANK);
     98      paramDefaults.put(FIELD_COMBINE_PARAM, FIELD_COMBINE_PARAM_AND);
     99      // paramDefaults.put(FIELD_CASE_PARAM, BOOLEAN_PARAM_ON);
     100      // paramDefaults.put(FIELD_STEM_PARAM, BOOLEAN_PARAM_OFF);
     101      // paramDefaults.put(FIELD_ACCENT_PARAM, BOOLEAN_PARAM_ON);
    96102    }
    97103
     
    108114            return false;
    109115        }
    110 
     116       
    111117        // Get the default level out of <defaultLevel> (buildConfig.xml)
    112118        Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
     
    260266    }
    261267
     268  // if field case/stem/accent defaults are not specified explicitly, we should use case/stem/accent defaults
     269  protected void getSearchParamDefaults(Element search_elem) {
     270   
     271    boolean found_f_stem = false;
     272    boolean found_f_case = false;
     273    boolean found_f_accent = false;
     274    NodeList param_defaults_list = GSXML.getChildrenByTagName(search_elem, GSXML.PARAM_DEFAULT_ELEM);
     275    for (int i=0; i<param_defaults_list.getLength(); i++) {
     276      Element paramdef = (Element)param_defaults_list.item(i);
     277      String name = paramdef.getAttribute(GSXML.NAME_ATT);
     278      String val = paramdef.getAttribute(GSXML.VALUE_ATT);
     279      if (!name.equals("") && !val.equals("")) {
     280    paramDefaults.put(name, val);
     281    if (name.equals(FIELD_STEM_PARAM)) {
     282      found_f_stem = true;
     283    } else if (name.equals(FIELD_CASE_PARAM)) {
     284      found_f_case = true;
     285    } else if (name.equals(FIELD_ACCENT_PARAM)) {
     286      found_f_accent = true;
     287    }
     288    if (!found_f_stem) {
     289      paramDefaults.put (FIELD_STEM_PARAM, paramDefaults.get(STEM_PARAM));
     290    }
     291    if (!found_f_case) {
     292      paramDefaults.put (FIELD_CASE_PARAM, paramDefaults.get(CASE_PARAM));
     293    }
     294    if (!found_f_accent) {
     295      paramDefaults.put (FIELD_ACCENT_PARAM, paramDefaults.get(ACCENT_PARAM));
     296    }
     297
     298      }
     299    }
     300  }
    262301    protected Element getServiceDescription(String service_id, String lang, String subset)
    263302    {
     
    393432    {
    394433        Element param = null;
     434        String param_default = paramDefaults.get(name);
    395435        if (name.equals(LEVEL_PARAM))
    396436        {
     
    416456            String[] vals1_texts = { getTextString("param." + RANK_PARAM + "." + RANK_PARAM_RANK, lang), getTextString("param." + RANK_PARAM + "." + RANK_PARAM_NONE, lang) };
    417457
    418             param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param." + RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts);
     458            param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param." + RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals1, vals1_texts);
    419459
    420460        }
     
    428468            String[] bool_ops = { "0", "1" };
    429469            String[] bool_texts = { getTextString("param.boolean.off", lang, "AbstractTextSearch"), getTextString("param.boolean.on", lang, "AbstractTextSearch") };
    430             param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, bool_ops, bool_texts);
     470            param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_BOOLEAN, param_default, bool_ops, bool_texts);
    431471
    432472        }
     
    454494            String[] val_texts = { getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_AND, lang), getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_OR, lang), getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_NOT, lang) };
    455495
    456             param = GSXML.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals, val_texts);
     496            param = GSXML.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals, val_texts);
    457497            param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
    458498        }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2TextSearch.java

    r26344 r28181  
    5656    protected boolean does_accent = false;
    5757
    58   // default values for stem indexes
    59   protected String case_default = BOOLEAN_PARAM_ON;
    60   protected String accent_default = BOOLEAN_PARAM_ON;
    61   protected String stem_default = BOOLEAN_PARAM_OFF;
    6258    // maxnumeric -
    6359    protected int maxnumeric = 4;
     
    186182            Document owner = info.getOwnerDocument();
    187183            Element config_search = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
    188 
    189             // work out what the default values for the stemming options are
    190             if (does_case || does_accent || does_stem) {
    191               // only bother looking for this is we have some of these set
    192               NodeList index_options = config_search.getElementsByTagName(GSXML.INDEX_OPTION_ELEM);
    193               for (int i = 0; i < index_options.getLength(); i++) {
    194                 Element ind = (Element) index_options.item(i);
    195                 String name = ind.getAttribute(GSXML.NAME_ATT);
    196                 String def_val = ind.getAttribute(GSXML.DEFAULT_ATT);
    197 
    198                 if (!def_val.equals("")) {
    199                   if (name.equals("stem")) {
    200                 stem_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
    201                   } else if (name.equals("casefold")) {
    202                 case_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
    203                   } else if (name.equals("accentfold")) {
    204                 accent_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
    205                   }
    206                 }
    207               }
    208             }
    209184
    210185            // so far we have index and indexSubcollection specific display elements, and global format elements
     
    354329        if (this.does_case)
    355330        {
    356             createParameter(CASE_PARAM, param_list, lang, case_default);
     331          createParameter(CASE_PARAM, param_list, lang);//, case_default);
    357332        }
    358333        if (this.does_stem)
    359334        {
    360             createParameter(STEM_PARAM, param_list, lang, stem_default);
     335          createParameter(STEM_PARAM, param_list, lang);//, stem_default);
    361336        }
    362337        if (this.does_accent)
    363338        {
    364             createParameter(ACCENT_PARAM, param_list, lang, accent_default);
     339          createParameter(ACCENT_PARAM, param_list, lang);//, accent_default);
    365340        }
    366341        createParameter(MATCH_PARAM, param_list, lang);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java

    r26042 r28181  
    2121// Greenstone classes
    2222import java.util.ArrayList;
     23import java.util.HashMap;
    2324
    2425import org.apache.log4j.Logger;
     
    7475    protected String default_index = "";
    7576
    76     protected String default_max_docs = "100";
    77 
    78     protected String default_hits_per_page = "10";
     77  protected HashMap<String, String> paramDefaults = null;
    7978
    8079    public AbstractSearch()
    8180    {
     81      paramDefaults = new HashMap<String, String>();
     82      paramDefaults.put(MAXDOCS_PARAM, "100");
     83      paramDefaults.put(HITS_PER_PAGE_PARAM, "10");
     84      paramDefaults.put(START_PAGE_PARAM, "1");
    8285    }
    8386
     
    108111        this.short_service_info.appendChild(tq_service);
    109112
     113        // load up any search param defaults
     114        Element search_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
     115        if (search_elem != null) {
     116          getSearchParamDefaults(search_elem);
     117        }
    110118        // add some format info to service map if there is any
    111119        // => lookin extra info first look in buildConfig
     
    115123        if (format == null)
    116124        {
    117             String path = GSPath.appendLink(GSXML.SEARCH_ELEM, GSXML.FORMAT_ELEM);
    118 
    119             // Note by xiao: instead of retrieving the first 'format'
    120             //   element inside the 'search' element, we are trying to
    121             //   find the real format element which has at least one
    122             //   'gsf:template' child element. (extra_info is
    123             //   collectionConfig.xml)
    124 
    125             //format = (Element) GSXML.getNodeByPath(extra_info, path);
    126 
    127             Element search_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
     125          // try to find a format element inside <search> that contains a gsf:template. Note what if we have only xsl:templates??
     126           
    128127            NodeList format_elems = null;
    129128            if (search_elem != null)
     
    169168    }
    170169
     170  protected void getSearchParamDefaults(Element search_elem) {
     171
     172    NodeList param_defaults_list = GSXML.getChildrenByTagName(search_elem, GSXML.PARAM_DEFAULT_ELEM);
     173    for (int i=0; i<param_defaults_list.getLength(); i++) {
     174      Element paramdef = (Element)param_defaults_list.item(i);
     175      String name = paramdef.getAttribute(GSXML.NAME_ATT);
     176      String val = paramdef.getAttribute(GSXML.VALUE_ATT);
     177      if (!name.equals("") && !val.equals("")) {
     178    paramDefaults.put(name, val);
     179      }
     180    }
     181  }
    171182    /**
    172183     * returns a basic description for QUERY_SERVICE. If a subclass provides
     
    273284        Element param = null;
    274285        String param_default = default_value;
    275 
     286        if (default_value == null) {
     287          // have we got a stored up default? will be null if not there
     288          param_default = paramDefaults.get(name);
     289        }
    276290        if (name.equals(QUERY_PARAM) || name.equals(RAW_PARAM))
    277291        {
     
    301315        else if (name.equals(MAXDOCS_PARAM))
    302316        {
    303             if (param_default == null)
    304             {
    305                 param_default = this.default_max_docs;
    306             }
    307 
    308317            param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_INTEGER, param_default, null, null);
    309318            param_list.appendChild(param);
     
    312321        else if (name.equals(HITS_PER_PAGE_PARAM))
    313322        {
    314             if (param_default == null)
    315             {
    316                 param_default = this.default_hits_per_page;
    317             }
    318 
    319323            param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_INTEGER, param_default, null, null);
    320324            param_list.appendChild(param);
     
    323327        else if (name.equals(START_PAGE_PARAM))
    324328        {
    325             if (param_default == null)
    326             {
    327                 param_default = "1";
    328             }
    329 
    330329            // start page - set to 1 for the search page
    331330            param = GSXML.createParameterDescription(this.doc, START_PAGE_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, param_default, null, null);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractTextSearch.java

    r26249 r28181  
    6060    public AbstractTextSearch()
    6161    {
     62      super();
    6263        // the search service
    6364        QUERY_SERVICE = "TextQuery";
     65        paramDefaults.put(CASE_PARAM, BOOLEAN_PARAM_ON);
     66        paramDefaults.put(STEM_PARAM, BOOLEAN_PARAM_OFF);
     67        paramDefaults.put(ACCENT_PARAM, BOOLEAN_PARAM_ON);
     68        paramDefaults.put(MATCH_PARAM, MATCH_PARAM_SOME);
    6469    }
    6570
     
    8792        Element param = null;
    8893        String param_default = default_value;
     94        if (default_value == null) {
     95          // have we got a stored up default? will be null if not there
     96          param_default = paramDefaults.get(name);
     97        }
    8998
    9099        if (super.createParameterChain(name, param_list, lang, default_value))
     
    94103        }
    95104        // otherwise look to see if it is a text specific parameter
    96         else if (name.equals(INDEX_SUBCOLLECTION_PARAM))
     105        if (name.equals(INDEX_SUBCOLLECTION_PARAM))
    97106        {
    98107            Element index_sub_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_SUBCOLLECTION_ELEM + GSXML.LIST_MODIFIER);
     
    137146        }
    138147    else if (name.equals(CASE_PARAM) || name.equals(STEM_PARAM) || name.equals(ACCENT_PARAM)) {
    139       if (param_default == null) {
    140         param_default = BOOLEAN_PARAM_OFF;
    141       }
    142148        String[] bool_ops = {"0", "1"};
    143149        String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)};
     
    146152        return true;
    147153    } else if (name.equals(MATCH_PARAM)) {
    148       if (param_default == null) {
    149         param_default = MATCH_PARAM_SOME;
    150       }
    151154     
    152155        String[] vals = {MATCH_PARAM_SOME, MATCH_PARAM_ALL };
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java

    r27950 r28181  
    102102        // we have case folding on by default
    103103        if (this.does_case) {
    104           mgpp_src.setCase(case_default.equals(BOOLEAN_PARAM_ON) ? true : false);
     104          mgpp_src.setCase(paramDefaults.get(CASE_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
    105105        }
    106106        if (this.does_stem) {
    107           mgpp_src.setStem(stem_default.equals(BOOLEAN_PARAM_ON) ? true : false);
     107          mgpp_src.setStem(paramDefaults.get(STEM_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
    108108        }
    109109        if (this.does_accent) {
    110           mgpp_src.setAccentFold(accent_default.equals(BOOLEAN_PARAM_ON) ? true : false);
     110          mgpp_src.setAccentFold(paramDefaults.get(ACCENT_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
    111111        }
    112112        // set up the query params
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java

    r25635 r28181  
    3737  extends GS2MGPPSearch {
    3838   static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
    39  
     39                       
     40  protected String default_max_docs = "-1";
     41  protected String default_hits_per_page = "30";
    4042    /** constructor */
    4143    public GoogleNgramMGPPSearch(){
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java

    r28061 r28181  
    4646    protected SharedSoleneQuery solene_src = null;
    4747
     48 
    4849    public SharedSoleneGS2FieldSearch()
    4950    {
     51      super();
    5052        // Lucene/Solr uses double operators, not single
    5153        AND_OPERATOR = "&&";
     
    5456        does_paging = true;
    5557        does_chunking = true;
     58        paramDefaults.put(SORT_ORDER_PARAM, SORT_ORDER_DESCENDING);
    5659    }
    5760
     
    6770        Element config_search = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
    6871        Document owner = info.getOwnerDocument();
    69         // get out the sort fields
     72        // find the sort fields in serviceRack xml, and add in the deisplayItems if any
    7073        NodeList sort_nodes = info.getElementsByTagName(SORT_ELEM);
    7174
     
    115118    {
    116119        Element param = null;
     120        String param_default = paramDefaults.get(name);
    117121        if (name.equals(RANK_PARAM))
    118122        {
     
    120124            ArrayList<String> fields = new ArrayList<String>();
    121125            ArrayList<String> field_names = new ArrayList<String>();
    122             if (getSortData(fields, field_names, lang)) {
    123 
    124               param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
     126            if (!getSortData(fields, field_names, lang)) {
     127              fields.add(RANK_PARAM_RANK);
     128              fields.add(RANK_PARAM_NONE);
     129              field_names.add(getTextString("param." + RANK_PARAM + "." + RANK_PARAM_RANK, lang));
     130              field_names.add(getTextString("param." + RANK_PARAM + "." + RANK_PARAM_NONE, lang));
    125131            }
     132           
     133            param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
     134           
    126135        } else if (name.equals(SORT_ORDER_PARAM)) {
    127136        String[] vals = { SORT_ORDER_ASCENDING, SORT_ORDER_DESCENDING };
    128137        String[] vals_texts = { getTextString("param." + SORT_ORDER_PARAM + "." + SORT_ORDER_ASCENDING, lang), getTextString("param." + SORT_ORDER_PARAM + "." + SORT_ORDER_DESCENDING, lang) };
    129138
    130         param = GSXML.createParameterDescription(this.doc, SORT_ORDER_PARAM, getTextString("param." + SORT_ORDER_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, SORT_ORDER_ASCENDING, vals, vals_texts);
     139        param = GSXML.createParameterDescription(this.doc, SORT_ORDER_PARAM, getTextString("param." + SORT_ORDER_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, SORT_ORDER_DESCENDING, vals, vals_texts);
    131140      }
    132141
Note: See TracChangeset for help on using the changeset viewer.