Changeset 3851 for trunk/gsdl3/src


Ignore:
Timestamp:
2003-03-11T16:58:35+13:00 (21 years ago)
Author:
kjdon
Message:

a wide variety of changes, next I will go through and make sure the code is tidy, nad tidy up teh xml a bit, but I wanted to check in all this first.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r3678 r3851  
    2828import org.w3c.dom.NodeList;
    2929/**
    30  * A ServicesImpl class for GSDL2-style Classifiers
     30 * A ServiceRack class for GSDL2-style Classifiers
    3131 *
    3232 * @author <a href="mailto:[email protected]">Katherine Don</a>
     
    5151    Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
    5252    display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM,  getTextString(service+".name", lang)));
    53     display.appendChild(GSXML.createTextElement(doc_,  GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
    54 
    55     Element param;
    56 
     53    //display.appendChild(GSXML.createTextElement(doc_,  GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
     54   
     55    // need to add in the classifier name info
     56    // add <classifier name="CL1">text name</classifier> to the
     57    // display node
     58    NodeList classifiers = config_info_.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     59    for (int i=0; i<classifiers.getLength(); i++) {
     60        Element cl = (Element)classifiers.item(i);
     61        Element disp = (Element)GSXML.getChildByTagName(cl, GSXML.DISPLAY_ELEM);
     62        String text = null;
     63        if (disp !=null) {
     64        text = GSXML.getDisplayText(disp,
     65                        GSXML.DISPLAY_NAME_ELEM,
     66                        lang, "en");
     67        }
     68        if (text == null || text.equals("")) {
     69        // no display element was specified, use the metadata name
     70        // for now this looks in the class properties file
     71        // this needs to use a general metadata thing instead
     72        text = getTextString(cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT), lang);
     73        }
     74       
     75        Element cl_elem = doc_.createElement(GSXML.CLASSIFIER_ELEM);
     76        cl_elem.setAttribute(GSXML.NAME_ATT, cl.getAttribute(GSXML.NAME_ATT));
     77        Element cl_name = GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, text);
     78        cl_elem.appendChild(cl_name);
     79       
     80        display.appendChild(cl_elem);
     81       
     82    }
     83   
    5784    return display;
    5885   
     
    90117    classifier.setAttribute(GSXML.NAME_ATT, classifier_name);
    91118    result_content.appendChild(classifier);
     119
     120    // see if there is a stylesheet associated with this classifier
     121    Element cl_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     122    Element cl_info = GSXML.getNamedElement(cl_list,
     123                        GSXML.CLASSIFIER_ELEM,
     124                        GSXML.NAME_ATT,
     125                        classifier_name);
     126    if (cl_info !=null) {
     127       
     128        // find the format child
     129        Element cl_format = (Element)GSXML.getChildByTagName(cl_info, GSXML.FORMAT_ELEM);
     130        // add it to the result if the result isnt null
     131        if (cl_format!=null) {
     132        System.out.println("adding format info to browse result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     133        result.appendChild(doc_.importNode(cl_format, true));
     134        }
     135    }
     136       
    92137    DBInfo top_info;
    93138
     
    98143    }
    99144
    100     // a substitute template - should be read from config file
    101     //String extra = "<stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='document' priority='3'><xsl:param name='collName'>coll-name</xsl:param><xsl:variable name='library' select='ancestor::page/config/library_name'/><td><a href='{$library}?a=r&amp;c={$collName}&amp;r={@name}'><img src='interfaces/default/images/book.gif' width='18' height='11' border='0'/></a></td><td>***</td><td><xsl:value-of select='metadataList/metadata[@name=\"Title\"]'/></td></xsl:template></stylesheet>";
    102     //Element extra_doc = converter_.getDOM(extra).getDocumentElement();
    103     //result.appendChild(doc_.importNode(extra_doc, true));
    104    
    105145    // get the classifier attributes
    106146    String type = top_info.getInfo("childtype");
     
    189229        Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    190230        GSXML.addMetadata(doc_, meta_list, "Title", title);
     231        String keyword = child_info.getInfo("Keyword");
     232        String source = child_info.getInfo("Source");
     233        GSXML.addMetadata(doc_, meta_list, "Keyword", keyword);
     234        GSXML.addMetadata(doc_, meta_list, "Source", source);
    191235        node.appendChild(meta_list);
    192236        this_node.appendChild(node);
     
    194238    }
    195239   
     240    System.out.println("result=");
     241    System.out.println(converter_.getString(result));
    196242    return result;
    197243   
     
    203249
    204250    System.out.println("configuring GS2Browse");
    205 
     251    System.out.println("config info=");
     252    System.out.println(converter_.getString(info));
    206253    Element e = null;
    207254    // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
     
    212259    short_service_info_.appendChild(e);
    213260
     261    // set up config info - just a cache of whats in the config file
     262    config_info_ = info;
     263
    214264    // set up service_info_map_ - for now, just has the same elements as above
    215265    // should have full details about each service incl params lists etc.
     
    217267    e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
    218268    e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
    219 
    220     // get the classifier list out of the service info
    221     Node classList = GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    222     e.appendChild(doc_.importNode(classList, true));
    223 
     269    Element cl_list = doc_.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     270    e.appendChild(cl_list);
     271
     272    // add in to the description a simplified list of classifiers
     273    NodeList classifiers = config_info_.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     274   
     275    for(int i=0; i<classifiers.getLength(); i++) {
     276        Element cl = (Element)classifiers.item(i);
     277        Element new_cl = (Element)doc_.importNode(cl, false); // just import this node, not the children
     278        cl_list.appendChild(new_cl);
     279       
     280    }
     281       
    224282    service_info_map_.put(CLASSIFIER_SERVICE, e);
    225283   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Construct.java

    r3681 r3851  
    6262    private static final String NEW_FILE_PARAM = "newfile";
    6363    private static final String HANDLE_PARAM = "id";
    64 
     64    private static final String BUILDTYPE_PARAM = "buildType";
     65    private static final String BUILDTYPE_MG = "mg";
     66    private static final String BUILDTYPE_MGPP = "mgpp";
     67   
    6568    // the list of the collections - store between some method calls
    6669    private String[] collection_list_ = null;
     
    107110    Element param;
    108111    if (service.equals(NEW_SERVICE)) {
    109         // have the coll title, about  and creator params
     112        // have the coll title, about, buildtype  and creator params
    110113        param = GSXML.createParameterDisplay(doc_, NEW_COL_TITLE_PARAM, getTextString("param."+NEW_COL_TITLE_PARAM, lang), null, null);
    111114        display.appendChild(param);
     
    113116        display.appendChild(param);
    114117        param = GSXML.createParameterDisplay(doc_, NEW_COL_ABOUT_PARAM, getTextString("param."+NEW_COL_ABOUT_PARAM, lang), null, null);
     118        display.appendChild(param);
     119
     120        String[] types = {BUILDTYPE_MGPP, BUILDTYPE_MG};
     121        String[] type_texts = {getTextString("param."+BUILDTYPE_PARAM+"."+BUILDTYPE_MGPP, lang), getTextString("param."+BUILDTYPE_PARAM+"."+BUILDTYPE_MG, lang)};
     122        param = GSXML.createParameterDisplay(doc_, BUILDTYPE_PARAM, getTextString("param."+BUILDTYPE_PARAM, lang), types, type_texts);
    115123        display.appendChild(param);
    116124    } else {
     
    396404    param = GSXML.createParameter(doc_, NEW_COL_ABOUT_PARAM, GSXML.PARAM_TYPE_TEXT, "", null);
    397405    param_list.appendChild(param);
     406    String[] types = {BUILDTYPE_MGPP, BUILDTYPE_MG};
     407    param = GSXML.createParameter(doc_, BUILDTYPE_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, BUILDTYPE_MGPP, types);
     408    param_list.appendChild(param);
     409
    398410    e.appendChild(param_list);
    399411    service_info_map_.put(NEW_SERVICE, e);
     
    627639        param.setAttribute(GSXML.VALUE_ATT, (String)params.get(NEW_COL_TITLE_PARAM));
    628640        param_list.appendChild(param);
     641        param = doc_.createElement(GSXML.PARAM_ELEM);
     642        param.setAttribute(GSXML.NAME_ATT, "buildtype");
     643        param.setAttribute(GSXML.VALUE_ATT, (String)params.get(BUILDTYPE_PARAM));
     644        param_list.appendChild(param);
    629645        return param_list;
    630646    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java

    r3820 r3851  
    7878
    7979
    80     /** Retrieve the structure of a document */
     80    /** Retrieve the structure of a document - this function needed as its called specifically on the class name*/
    8181    protected Element processDocumentStructureRetrieve(Element request)
    8282    {
     
    8585
    8686
    87     /** Retrieve metadata associated with a document */
     87    /** Retrieve metadata associated with a document - this function needed as its called specifically on the class name*/
    8888    protected Element processDocumentMetadataRetrieve(Element request)
    8989    {
     
    106106    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    107107    if (param_list == null) {
    108         System.err.println("GS2Retrieve, DocumentContentRetrieve Error: missing paramList.\n");
     108        System.err.println("GS2MGPPRetrieve, DocumentContentRetrieve Error: missing paramList.\n");
    109109        return result;  // Return the empty result
    110110    }
     
    113113
    114114    // Process the request parameters
     115    // are there any???
    115116    Element param = (Element) param_list.getFirstChild();
    116117    while (param != null) {
     
    119120        }
    120121        else {
    121         //
     122        // this looks for a level param but I think we dont use it
    122123        if (param.getAttribute(GSXML.NAME_ATT) == LEVEL_PARAM) {
    123124            level = GSXML.getValue(param);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java

    r3826 r3851  
    4747    extends GS2Search {
    4848
    49     // these strings must match what is found in the properties file
    50     // the services on offer
     49    // extra services offered by mgpp collections
    5150    private static final String FIELD_QUERY_SERVICE = "FieldQuery";
    5251    private static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery";
    5352
    54     // Parameters used
    55     private static final String INDEX_PARAM = "index";
     53    // extra parameters used
    5654    private static final String LEVEL_PARAM = "level";
    5755    private static final String RANK_PARAM = "sortBy";
     
    7068    private static final String FIELD_COMBINE_PARAM_NOT = "2";
    7169
    72     // Elements used in the config file that are specific to this class
    73     private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
    74     private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
    75     private static final String INDEX_ELEM = "index";
    76     private static final String LEVEL_ELEM = "level";
    77 
     70    private static final int TEXT_QUERY = 0;
     71    private static final int SIMPLE_QUERY = 1;
     72    private static final int ADVANCED_QUERY = 2;
     73   
     74    protected static final String FIELD_ATT = "field";
    7875    private MGPPWrapper mgpp_src_=null;
    7976
    80     private String default_index_=null;
    8177    private String default_level_=null;
    82 
    8378   
    8479    /** constructor */
     
    9994    System.out.println("Configuring GS2MGPPSearch...");
    10095
    101     // Get the default index out of <defaultIndex> (buildConfig.xml)
    102     Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
    103     if (def != null) {
    104         default_index_ = def.getAttribute(GSXML.NAME_ATT);
    105     }
    106     if (default_index_ == null || default_index_.equals("")) {
    107         System.err.println("Error: default index not specified!");
    108         return false;
    109     }
    110     // System.out.println("Default index: " + default_index_);
    111 
    11296    // Get the default level out of <defaultLevel> (buildConfig.xml)
    113     def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
     97    Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
    11498    if (def != null) {
    11599        default_level_ = def.getAttribute(GSXML.NAME_ATT);
     
    119103        return false;
    120104    }
    121     // System.out.println("Default level: " + default_level_);
    122105
    123106    // the default level is also the level which gdbm is expecting
    124107    mgpp_src_.setReturnLevel(default_level_);
     108    mgpp_src_.setReturnTerms(true);
     109    mgpp_src_.setQueryLevel(default_level_);
    125110
    126111    // set up which services are available for this collection
     
    140125    // set up service_info_map_ - for now, just has the same elements as above
    141126    // should have full details about each service incl params lists etc.
    142     // do the text query one - for now a static list. later use buildcfg.xml values to dynamically change this
    143127    Element fq_service_full = (Element) fq_service.cloneNode(true);
    144128    Element fq_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     
    168152        if (len > 1) { // add index param to list only if more than one index specified
    169153        String [] inds  = new String[len];
     154        String [] ind_names = new String[len];
    170155        for (int i=0; i<len; i++) {
    171156            inds[i] = ((Element)indexes.item(i)).getAttribute(GSXML.NAME_ATT);
     157            if (display) {
     158            Element disp = (Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAY_ELEM);
     159            ind_names[i] = GSXML.getDisplayText(disp, GSXML.DISPLAY_NAME_ELEM, lang, "en");
     160            }
     161            //Element display_name = (Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAYNAME_ELEM)
     162            //ind_names[i] = GSXML.getNodeText((Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAYNAME_ELEM));
     163            // }
    172164        }
    173165        if (display) {
    174166            // use the same index names for now - should get these out of the config info
    175             param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, inds);
     167            param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, ind_names);
    176168        } else {
    177169            param = GSXML.createParameter(doc_, INDEX_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_index_, inds);
     
    185177        if (len > 1) { // add level param to list only if more than one index specified
    186178        String [] levs  = new String[len];
     179        String [] lev_names = new String[len];
    187180        for (int i=0; i<len; i++) {
    188181            levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT);
     182            if (display) {
     183            String lname = "level."+levs[i];
     184            System.out.println("lname="+lname);
     185            //lev_names[i] = levs[i];
     186            lev_names[i] = getTextString(lname, lang);
     187            }
    189188        }
    190189        if (display) {
    191             param =  GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, levs);
     190            param =  GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, lev_names);
    192191        } else {
    193192            param = GSXML.createParameter(doc_, LEVEL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_level_, levs);
     
    231230       
    232231        }
     232
    233233    } else if (name.equals(FIELD_FIELD_PARAM)) {
    234234       
    235         // the field list - should be read from config file
    236         String [] vals2 = {"TX", "SU", "TI", "OR"};
    237         String [] vals2_texts = {"TextOnly", "Subject", "Title", "Organization"};
     235        // the field list -  read from config file
     236        Element field_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.FIELD_ELEM+GSXML.LIST_MODIFIER);
     237        NodeList fields = field_list.getElementsByTagName(GSXML.FIELD_ELEM);
     238        int len = fields.getLength();
     239        String [] f_names = new String [len];
     240        String [] f_texts = new String [len];
     241
     242        for (int i=0; i< len;i++) {
     243        f_names[i] = ((Element)fields.item(i)).getAttribute(GSXML.SHORTNAME_ATT);
     244        if (display) {
     245            // these should be changed to a text element based on lang
     246            f_texts[i] = ((Element)fields.item(i)).getAttribute(GSXML.NAME_ATT);
     247        }
     248
     249        }
     250        // String [] vals2 = {"TX", "SU", "TI", "OR"};
     251        //String [] vals2_texts = {"TextOnly", "Subject", "Title", "Organization"};
    238252       
    239253        if (display) {
    240         param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), vals2, vals2_texts);
     254        param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), f_names, f_texts);
    241255       
    242256        } else {
    243         param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", vals2 );
     257        param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", f_names );
    244258       
    245259        }
     
    273287     * otherwise it creates the description version
    274288     */
    275     protected boolean createTextQueryParamList(Element param_list, boolean display,
     289    protected boolean createTextQueryParamList(Element param_list,
     290                           boolean display,
    276291                           String lang)
    277292    {
     
    280295    createParameter(INDEX_PARAM, param_list, display, lang);
    281296    createParameter(LEVEL_PARAM, param_list, display, lang);
     297    createParameter(CASE_PARAM, param_list, display, lang);
     298    createParameter(STEM_PARAM, param_list, display, lang);
     299    createParameter(MATCH_PARAM, param_list, display, lang);
    282300    createParameter(RANK_PARAM, param_list, display, lang);
    283     return super.createTextQueryParamList(param_list, display, lang);
    284     }
     301    createParameter(MAXDOCS_PARAM, param_list, display, lang);
     302    createParameter(QUERY_PARAM, param_list, display, lang);
     303
     304    return true;
     305    }
     306
     307
     308    // for now, the field queries just use the default index.
     309    // however, it is entirely possible to create two indexes with different
     310    // metadata. then you run into problems with displaying the form - you
     311    // need to use javascript to change teh field and maybe level lists
     312    // depending on which index is selected, or have the index preselected
     313    // before going to the query form
    285314
    286315
     
    292321                        String lang)
    293322    {
     323    createParameter(LEVEL_PARAM, param_list, display, lang);
    294324    createParameter(MATCH_PARAM, param_list, display, lang);
    295     createParameter(LEVEL_PARAM, param_list, display, lang);
    296325    createParameter(CASE_PARAM, param_list, display, lang);
    297326    createParameter(STEM_PARAM, param_list, display, lang);
     
    386415    return display;
    387416    }
    388 
    389417   
     418    // the following three functions are needed so the base class can
     419    // call the process+SERVICE_NAME methods
    390420    /** process a text query */
    391     protected Element processTextQuery(Element request)
     421    protected Element processTextQuery(Element request) {
     422    return processAnyQuery(request, TEXT_QUERY);
     423    }
     424
     425    /** process a field query */   
     426    protected Element processFieldQuery(Element request) {
     427    return processAnyQuery(request, SIMPLE_QUERY);
     428    }
     429
     430    /** process an advanced field query */
     431    protected Element processAdvancedFieldQuery(Element request) {
     432    return processAnyQuery(request, ADVANCED_QUERY);
     433    }
     434   
     435    /** process a  query */
     436    protected Element processAnyQuery(Element request, int query_type)
    392437    {
     438
     439    String service_name=null;
     440    String empty_query_test_param=null;
     441    // set up the type specific bits
     442    switch (query_type) {
     443    case TEXT_QUERY:
     444        service_name = TEXT_QUERY_SERVICE;
     445        empty_query_test_param = QUERY_PARAM;
     446        break;
     447    case SIMPLE_QUERY:
     448        service_name = FIELD_QUERY_SERVICE;
     449        empty_query_test_param = FIELD_QUERY_PARAM;
     450        break;
     451    case ADVANCED_QUERY:
     452        service_name = ADVANCED_FIELD_QUERY_SERVICE;
     453        empty_query_test_param = FIELD_QUERY_PARAM;
     454        break;
     455    default:
     456        // should never get here
     457        System.out.println("wrong query type!!");
     458        return null;
     459    }
     460   
    393461    // Create a new (empty) result message
    394462    Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
    395     String from = GSPath.appendLink(cluster_name_, TEXT_QUERY_SERVICE);
     463    // set the from att
     464    String from = GSPath.appendLink(cluster_name_, service_name);
    396465    result.setAttribute(GSXML.FROM_ATT, from);
    397466    result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    398467    Element result_content = doc_.createElement(GSXML.CONTENT_ELEM);
    399468    result.appendChild(result_content);
    400 
     469   
    401470    // Get the parameters of the request
    402471    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     
    410479
    411480    // Make sure a query has been specified
    412     String query = (String) params.get(QUERY_PARAM);
     481    String query = (String) params.get(empty_query_test_param);
    413482    if (query == null || query == "") {
    414483        return result;  // Return the empty result
     
    421490    }
    422491
    423     // The location of the MGPP text files
     492    // set up mgpp_src
    424493    String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_);
    425494    String indexdir = GSFile.collectionIndexPath(cluster_name_, index);
     
    428497
    429498    mgpp_src_.loadIndexData(basedir, indexdir);
    430 
    431499    setStandardQueryParams(params);
     500   
     501    // if field search, create the query string
     502    switch (query_type) {
     503    case SIMPLE_QUERY:
     504        query = parseFieldQueryParams(params);
     505        break;
     506    case ADVANCED_QUERY:
     507        query = parseAdvancedFieldQueryParams(params);
     508        break;
     509    }
     510    // run the query
    432511        mgpp_src_.runQuery(query);
    433512    MGPPQueryResult mqr= mgpp_src_.getQueryResult();
    434     long totalDocs = mqr.getTotalDocs();
    435     System.out.println("Total documents: " + totalDocs);
    436 
    437     // Get the docnums out, and convert to HASH ids
    438     Vector docs = mqr.getDocs();
    439     if (docs.size()==0) {
    440         System.out.println("Warning: No results found...\n");
    441         // return result;
    442     }
    443 
     513
     514    // build up the response
     515   
    444516    // Create a metadata list to store information about the query results
    445517    Element metadata_list = GSXML.addMetaList(doc_, result);
    446518
    447519    // Add a metadata element specifying the number of matching documents
     520    long totalDocs = mqr.getTotalDocs();
    448521    Element num_matches_elem = doc_.createElement(GSXML.METADATA_ELEM);
    449522    num_matches_elem.setAttribute(GSXML.NAME_ATT, "numDocsMatched");
     
    452525
    453526    // Create a document list to store the matching documents, and add them
     527    Vector docs = mqr.getDocs();
    454528    Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
    455529    result_content.appendChild(document_list);
     
    462536
    463537    // Create a term list to store the term information, and add it
     538    String query_level = (String)params.get(LEVEL_PARAM); // the current query level
    464539    Element term_list = doc_.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
    465540    result_content.appendChild(term_list);
     
    467542    for (int t = 0; t < terms.size(); t++) {
    468543        MGPPTermInfo term_info = (MGPPTermInfo) terms.get(t);
    469 
    470         String term = term_info.term_;
    471         int stem_method = term_info.stem_method_;
     544       
     545        Element term_elem = doc_.createElement(GSXML.TERM_ELEM);
     546        term_elem.setAttribute(GSXML.NAME_ATT, term_info.term_);
     547        term_elem.setAttribute(STEM_ATT, "" + term_info.stem_method_);
     548        term_elem.setAttribute(FREQ_ATT, "" + term_info.term_freq_);
     549        term_elem.setAttribute(NUM_DOCS_MATCH_ATT, "" + term_info.match_docs_);
     550        String field = term_info.tag_;
     551        if (field.equals(query_level)) {
     552        // ignore
     553        field = "";
     554        }
     555        term_elem.setAttribute(FIELD_ATT, field);
     556       
    472557        Vector equiv_terms = term_info.equiv_terms_;
    473 
    474         Element term_elem = doc_.createElement(GSXML.TERM_ELEM);
    475         term_elem.setAttribute(GSXML.NAME_ATT, term);
    476         term_elem.setAttribute(STEM_ATT, "" + stem_method);
    477 
    478558        Element equiv_term_list = doc_.createElement(EQUIV_TERM_ELEM+GSXML.LIST_MODIFIER);
    479559        term_elem.appendChild(equiv_term_list);
    480 
     560       
    481561        for (int et = 0; et < equiv_terms.size(); et++) {
    482562        String equiv_term = (String) equiv_terms.get(et);
     
    489569        }
    490570
    491         term_elem.setAttribute(FREQ_ATT, "" + term_info.term_freq_);
    492571        term_list.appendChild(term_elem);
    493572    }
     
    495574    return result;
    496575    }
    497 
    498 
    499     protected Element processFieldQuery(Element request) {
    500     return processAnyFieldQuery(request, "simple");
    501     }
    502 
    503 
    504     protected Element processAdvancedFieldQuery(Element request) {
    505     return processAnyFieldQuery(request, "advanced");
    506     }
    507 
    508 
    509     /** process a fielded query */
    510     protected Element processAnyFieldQuery(Element request, String type) {
    511    
    512     System.out.println("processing any Field Query...");
    513     Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
    514     String from = null;
    515     if (type.equals("simple")) {
    516         from = GSPath.appendLink(cluster_name_, FIELD_QUERY_SERVICE);
    517     } else {
    518         from = GSPath.appendLink(cluster_name_, ADVANCED_FIELD_QUERY_SERVICE);
    519     }
    520     result.setAttribute(GSXML.FROM_ATT, from);
    521     result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
    522    
    523     // get param list
    524     Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    525     if (param_list==null) {
    526         System.err.println("GS2MGPPSearch, FieldQuery Error: no param list in request!");
    527         return result; // empty result
    528     }
    529 
    530     HashMap params = GSXML.extractAllParams(param_list);
    531     printHash(params);
    532 
    533     //check one of the params to see if it is present
    534     String test_param = (String)params.get(FIELD_QUERY_PARAM);
    535     if (test_param == null) { // no query
    536         return result;
    537     }
    538 
    539     // for now we are using the default index
    540     String index = default_index_;
    541    
    542     // now set up the mgpp stuff
    543     String basedir = GSFile.collectionBaseDir(site_home_,
    544                           cluster_name_);
    545     String indexdir = GSFile.collectionIndexPath(cluster_name_, index);
    546    
    547     mgpp_src_.loadIndexData(basedir, indexdir);
    548     setStandardQueryParams(params);
    549    
    550     String query="";
    551     if (type.equals("simple")) {
    552         query = parseFieldQueryParams(params);
    553     } else if (type.equals("advanced")) {
    554         query = parseAdvancedFieldQueryParams(params);
    555     }
    556     System.out.println("query="+query);
    557     mgpp_src_.runQuery(query);
    558     MGPPQueryResult mqr= mgpp_src_.getQueryResult();
    559    
    560     // get the docnums out, and convert to HASH ids
    561     Vector docs = mqr.getDocs();
    562     if (docs.size()==0) {
    563         // no docs found
    564         return result;
    565     }
    566     // create a documentList element
    567     Element c = doc_.createElement(GSXML.CONTENT_ELEM);
    568     result.appendChild(c);
    569     Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
    570     c.appendChild(document_list);
    571     // add each document
    572     for (int d=0; d<docs.size(); d++) {
    573         long docnum = ((MGPPDocInfo)docs.elementAt(d)).num_;
    574         String id = gdbm_src_.docnum2Oid(docnum);
    575         Element doc_node = createDocumentNodeElement(id);
    576         document_list.appendChild(doc_node);
    577     }
    578     return result;
    579     }
    580 
    581 
    582576
    583577    // should probably use a list rather than map
    584578    protected boolean setStandardQueryParams(HashMap params) {
    585579
    586     // set the default ones
    587     mgpp_src_.setReturnTerms(true);
    588580    Set entries = params.entrySet();
    589581    Iterator i = entries.iterator();
     
    620612    }
    621613
     614    /** combines all the field params into a single query
     615     * - for simple field query */
    622616    protected String parseFieldQueryParams(HashMap params) {
    623617
     
    644638    return final_query.toString();
    645639    }
    646    
     640
     641    /** combines all the field params into a single query
     642     * - for advanced field query */   
    647643    protected String parseAdvancedFieldQueryParams(HashMap params) {
    648644
     
    697693    }
    698694    }
     695   
    699696    protected String addStemAndCase(String q, String s, String c) {
    700697    String mods = "#";
     
    721718    }
    722719
    723     protected void printHash(HashMap map) {
    724     System.out.println("Map entries are :");
    725     Set entries = map.entrySet();
    726     Iterator i = entries.iterator();
    727     while (i.hasNext()) {
    728         Map.Entry m = (Map.Entry)i.next();
    729         String name = (String)m.getKey();
    730         String value = (String)m.getValue();
    731         System.out.println(name+"="+value);
    732     } 
    733     }
    734720
    735721}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java

    r3823 r3851  
    44 *
    55 *    This program is free software; you can redistribute it and/or modify
    6  *    it under the terms of the GNU General Public License as published by
    7  *    the Free Software Foundation; either version 2 of the License, or
     6 *   the Free Software Foundation; either version 2 of the License, or
    87 *    (at your option) any later version.
    98 *
     
    4140 *
    4241 * @author <a href="mailto:[email protected]">Katherine Don</a>
     42 * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
    4343 * @version $Revision$
    4444 */
     
    4747    extends GS2Search {
    4848
    49     // Parameters used
    50     private static final String INDEX_PARAM = "index";
    51 
    52     // Elements used in the config file that are specific to this class
    53     private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
    54     private static final String INDEX_ELEM = "index";
    5549
    5650    private MGWrapper mg_src_ = null;
    57 
    58     private String default_index_ = null;
    5951
    6052
     
    6759
    6860    /** configure this service */
    69     public boolean configure(Element info)
     61    /*    public boolean configure(Element info)
    7062    {
    7163    // Do generic configuration
     
    7668    System.out.println("Configuring GS2MGSearch...");
    7769
    78     // Get the default index out of <defaultIndex> (buildConfig.xml)
    79     Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
    80     if (def != null) {
    81         default_index_ = def.getAttribute(GSXML.NAME_ATT);
    82     }
    83     if (default_index_ == null || default_index_.equals("")) {
    84         System.err.println("Error: default index not specified!");
    85         return false;
    86     }
    87     // System.out.println("Default index: " + default_index_);
    88 
    8970    return true;
    90     }
     71    }*/
    9172
    9273
     
    136117    // the query form
    137118    createParameter(INDEX_PARAM, param_list, display, lang);
    138     return super.createTextQueryParamList(param_list, display, lang);
     119    createParameter(CASE_PARAM, param_list, display, lang);
     120    createParameter(STEM_PARAM, param_list, display, lang);
     121    createParameter(MATCH_PARAM, param_list, display, lang);
     122    createParameter(MAXDOCS_PARAM, param_list, display, lang);
     123    createParameter(QUERY_PARAM, param_list, display, lang);
     124
     125    return true;
    139126    }
    140127
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Search.java

    r3822 r3851  
    3030/**
    3131 *
    32  * @author <a href="mailto:[email protected]">Katherine Don</a>
     32 * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
    3333 * @version $Revision$
    3434 */
     
    4242
    4343    // Parameters used
     44    protected static final String INDEX_PARAM = "index";
    4445    protected static final String CASE_PARAM = "case";
    4546    protected static final String STEM_PARAM = "stem";
     
    5859    protected static final String FREQ_ATT = "freq";
    5960
     61    // Elements used in the config file that are specific to this class
     62    protected static final String DEFAULT_INDEX_ELEM = "defaultIndex";
     63    protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
     64    protected static final String INDEX_ELEM = "index";
     65    protected static final String LEVEL_ELEM = "level";
     66
    6067    protected GDBMWrapper gdbm_src_ = null;
    6168
    6269    protected Element config_info_ = null;
     70
     71    /** the default index */
     72    protected String default_index_ = null;
    6373
    6474
     
    7585    System.out.println("Configuring GS2Search...");
    7686    config_info_ = info;
     87
     88    // Get the default index out of <defaultIndex> (buildConfig.xml)
     89    Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
     90    if (def != null) {
     91        default_index_ = def.getAttribute(GSXML.NAME_ATT);
     92    }
     93    if (default_index_ == null || default_index_.equals("")) {
     94        System.err.println("Error: default index not specified!");
     95        return false;
     96    }
    7797
    7898    // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
     
    103123
    104124    /** creates a new param element and adds it to the param list */
    105     protected void createParameter(String name, Element param_list, boolean display,
    106                    String lang)
     125    protected void createParameter(String name, Element param_list,
     126                   boolean display, String lang)
    107127    {
    108128    Element param=null;
     
    162182     * otherwise it creates the description version
    163183     */
    164     protected boolean createTextQueryParamList(Element param_list, boolean display,
    165                            String lang)
    166     {
    167     // the order they are specified here is the order they appear on
    168     // the query form
    169     createParameter(CASE_PARAM, param_list, display, lang);
    170     createParameter(STEM_PARAM, param_list, display, lang);
    171     createParameter(MATCH_PARAM, param_list, display, lang);
    172     createParameter(MAXDOCS_PARAM, param_list, display, lang);
    173     createParameter(QUERY_PARAM, param_list, display, lang);
    174     return true;
    175     }
    176 
     184    protected abstract boolean createTextQueryParamList(Element param_list,
     185                            boolean display,
     186                            String lang);
    177187
    178188    /** creates a display element containing all the text strings needed to display
     
    182192    // Create a service display for the basic text query service
    183193    Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
    184     display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM,
    185                             getTextString(service+".name", lang)));
    186     display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM,
    187                             getTextString(service+".submit", lang)));
     194    display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, getTextString(service+".name", lang)));
     195    display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
    188196
    189197    // now need to add in the params
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java

    r3677 r3851  
    6969    /** a converter class to create Documents etc */
    7070    protected XMLConverter converter_ = null;
     71
     72    /** the original config info - if need to store it */
     73    protected Element config_info_ = null;
    7174
    7275    /** XML element for describe requests - the container doc */
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/XSLTServices.java

    r3648 r3851  
    100100  }
    101101 
    102   /** configure this service */
    103   public boolean configure(Element info) {
    104    
    105     System.out.println("configuring XSLTServices");
    106     config_info_ = info;
     102    /** configure this service */
     103    public boolean configure(Element info) {
     104     
     105      System.out.println("configuring XSLTServices");
     106      config_info_ = info;
    107107    try {
    108108      System.out.println("XSLTService::configure() called with:");
Note: See TracChangeset for help on using the changeset viewer.