Changeset 5191


Ignore:
Timestamp:
2003-08-19T14:46:30+12:00 (21 years ago)
Author:
kjdon
Message:

now we are doing query results paging in tehaction, not the xslt - this saves us retrieving metadata for docs which are not displayed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java

    r5155 r5191  
    2929    // create the return message
    3030    Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    31     // for now we only have one type of query - subaction not used
    3231    Element response = basicQuery(request);
    3332    result.appendChild(this.doc.importNode(response, true));
     
    3635   
    3736    /** a generic query handler
    38      * this gets the service description, does the query (just passes all teh
     37     * this gets the service description, does the query (just passes all the
    3938     * params to the service, then gets the titles for any results
    4039     */
     
    112111        return page_response;
    113112    }
    114     Element query_param_list = GSXML.createParameterList(this.doc, service_params);//(Element)this.doc.importNode(cgi_param_list, true);
    115     System.out.println("service params are "+this.converter.getString(query_param_list));
     113    Element query_param_list = GSXML.createParameterList(this.doc, service_params);
     114    ///ystem.out.println("service params are "+this.converter.getString(query_param_list));
    116115    mr_query_request.appendChild(query_param_list);
    117116
     
    145144    }
    146145   
    147     // do the metadata request
     146    // paging of the results is done here - we filter the list to remove unwanted entries before retrieving metadata
     147    Element filtered_doc_list = filterDocList(params, service_description, document_list);
     148   
     149    // do the metadata request on the filtered list
    148150    Element mr_metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    149151    Element mr_metadata_request = this.doc.createElement(GSXML.REQUEST_ELEM);
     
    164166   
    165167    // add in the doc node list too
    166     mr_metadata_request.appendChild(this.doc.importNode(document_list, true));
     168    mr_metadata_request.appendChild(filtered_doc_list);
     169
    167170    Element mr_metadata_response = (Element) this.mr.process(mr_metadata_message); 
    168171   
     
    177180    return page_response;
    178181    }
     182
     183    /** this filters out some of the doc results for result paging */
     184    protected Element filterDocList(HashMap params, Element service_description, Element orig_doc_list) {
     185   
     186    // check in the service descripiton to see if hitsPerpage is a param
     187    Element service_p_list = (Element)GSXML.getChildByTagName(service_description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     188    Element hits_param = GSXML.getNamedElement(service_p_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "hitsPerPage");
     189   
     190    boolean service_paging = false;
     191    if (hits_param != null) {
     192        service_paging = true;
     193    }
     194    if (service_paging) {
     195        // the service is doing the paging, so we want to display all of teh returned docs
     196        return (Element)this.doc.importNode(orig_doc_list, true);
     197    }
     198   
     199    String hits_pp = (String)params.get("hitsPerPage");
     200    int hits = 20;
     201    if (hits_pp != null && !hits_pp.equals("")) {
     202        try {
     203        hits = Integer.parseInt(hits_pp);
     204        } catch (Exception e) {
     205        hits=20;
     206        }
     207    }
     208
     209    if (hits == -1) { // all
     210        return (Element)this.doc.importNode(orig_doc_list, true);
     211    }
     212    NodeList result_docs = orig_doc_list.getElementsByTagName(GSXML.DOC_NODE_ELEM);
     213   
     214    int num_docs = result_docs.getLength();
     215    if (num_docs <= hits) {
     216        // too few docs to do paging
     217        return (Element)this.doc.importNode(orig_doc_list, true);
     218    }
     219
     220    // now we need our own doc list
     221    Element result_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     222    String start_p = (String)params.get("startPage");
     223    int start = 1;
     224    if (start_p != null && !start_p.equals("")) {
     225        try {
     226        start = Integer.parseInt(start_p);
     227        } catch (Exception e) {
     228        start = 1;
     229        }
     230    }
     231
     232    int start_from = (start-1)*hits;
     233    int end_at = (start*hits)-1;
     234
     235    if (start_from > num_docs) {
     236        // something has gone wrong
     237        return result_list;
     238    }
     239   
     240    if (end_at > num_docs) {
     241        end_at = num_docs-1;
     242    }
     243
     244    // now we finally have the docs numbers to use
     245    for (int i=start_from; i<=end_at; i++) {
     246        result_list.appendChild(this.doc.importNode(result_docs.item(i), true));
     247    }
     248
     249    return result_list;
     250    }
     251
    179252}
Note: See TracChangeset for help on using the changeset viewer.