Changeset 29557


Ignore:
Timestamp:
2014-12-08T14:44:06+13:00 (9 years ago)
Author:
kjdon
Message:

paging search results. hits per page param done by action now if not provided by service. not done in xslt.

File:
1 edited

Legend:

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

    r28964 r29557  
    2020{
    2121
     22  public static final String HITS_PER_PAGE = "hitsPerPage";
    2223    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.QueryAction.class.getName());
    23 
     24 
    2425    /**
    2526     * process - processes a request.
     
    5859        String service_name = (String) params.get(GSParams.SERVICE);
    5960        String collection = (String) params.get(GSParams.COLLECTION);
    60 
     61        String lang = request.getAttribute(GSXML.LANG_ATT);
    6162        // collection may be null or empty when we are doing cross coll services
    6263        if (collection == null || collection.equals(""))
     
    7980        page_response.appendChild(doc.importNode(format_elem, true));
    8081
    81         if (request_type.indexOf("d") != -1)
    82         {
     82        //if (request_type.indexOf("d") != -1)
     83        //{
     84        // get the service description
    8385            // we have been asked for the service description
    8486            Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     
    9395
    9496            Element service_description = (Element) doc.importNode(GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM), true);
    95             page_response.appendChild(service_description);
    96         }
    97 
     97
     98
     99            // have we been asked to return it as part of the response?
     100            if (request_type.indexOf("d") != -1) {
     101              page_response.appendChild(service_description);
     102            }
     103            //}
     104        boolean does_paging = false;
     105        Element meta_list =(Element) GSXML.getChildByTagName(service_description, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     106        if (meta_list != null) {
     107          String value = GSXML.getMetadataValue(meta_list, "does_paging");
     108          if (value.equals("true")) {
     109            does_paging = true;
     110          }
     111        }
     112
     113        if (does_paging == false) {
     114          // we will do the paging, so lets add in a hitsPerPage param to the service
     115          addHitsParamToService(doc, service_description, lang);
     116        }
    98117        if (request_type.indexOf("r") == -1)
    99118        {
     
    124143        mr_query_request.appendChild(query_param_list);
    125144
    126         logger.debug(GSXML.xmlNodeToString(mr_query_message));
    127 
    128145        // do the query
    129146        Element mr_query_response = (Element) this.mr.process(mr_query_message);
     
    186203        if (doc_metadata.getLength() > 0)
    187204        {
    188             logger.error("have already found metadata!");
    189             // append the doc list to the result
     205          // why are we not paging these results?????
     206          // append the doc list to the result
    190207            page_response.appendChild(doc.importNode(document_list, true));
    191208            //append site metadata
     
    205222
    206223        // paging of the results is done here - we filter the list to remove unwanted entries before retrieving metadata
    207         Element filtered_doc_list = filterDocList(doc, params, service_params, document_list);
    208 
     224        Element filtered_doc_list;
     225        if (does_paging) {
     226          filtered_doc_list = (Element)doc.importNode(document_list, true);
     227        } else {
     228          filtered_doc_list = filterDocList(doc, params, service_params, document_list);
     229        }
    209230        // do the metadata request on the filtered list
    210231        Element mr_metadata_message = doc.createElement(GSXML.MESSAGE_ELEM);
     
    251272        }
    252273
    253         logger.debug("Query page:\n" + this.converter.getPrettyString(page_response));
     274        //logger.debug("Query page:\n" + this.converter.getPrettyString(page_response));
    254275        //append site metadata
    255276        addSiteMetadata(page_response, userContext);
     
    262283    {
    263284
    264         // check the hits_per_page param - is it a service param??
    265         String hits_pp = (String) service_params.get("hitsPerPage");
    266         if (hits_pp == null)
    267         {
    268             // the service is doing the paging, so we want to display all of the returned docs(???)
    269             //    return (Element)doc.importNode(orig_doc_list, true);
    270             // try hitsPerPage in the globle param
    271             hits_pp = (String) params.get("hitsPerPage");
    272         }
    273 
     285      String hits_pp = (String) service_params.get(HITS_PER_PAGE);
     286     
    274287        int hits = 20;
    275288        if (hits_pp != null && !hits_pp.equals(""))
    276289        {
     290          if (hits_pp.equals("all")) {
     291            hits = -1;
     292          } else {
    277293            try
    278294            {
     
    283299                hits = 20;
    284300            }
    285         }
    286 
     301          }
     302        }
    287303        if (hits == -1)
    288304        { // all
     
    319335            }
    320336        }
    321 
    322337        int start_from = (start - 1) * hits;
    323338        int end_at = (start * hits) - 1;
     
    333348            end_at = num_docs - 1;
    334349        }
    335 
    336350        // now we finally have the docs numbers to use
    337351        for (int i = start_from; i <= end_at; i++)
     
    343357    }
    344358
     359  protected boolean addHitsParamToService(Document doc, Element service_description, String lang) {
     360    Element param_list = (Element)GSXML.getChildByTagName(service_description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     361    Element param = GSXML.createParameterDescription(doc, HITS_PER_PAGE, getTextString("param." + HITS_PER_PAGE, lang, "AbstractSearch", null), GSXML.PARAM_TYPE_INTEGER, "20", null, null);
     362    Element query_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "query");
     363    if (query_param != null) {
     364      param_list.insertBefore(param, query_param);
     365    } else {
     366      param_list.appendChild(param);
     367    }
     368    return true;
     369  }
    345370}
Note: See TracChangeset for help on using the changeset viewer.