Changeset 30150

Show
Ignore:
Timestamp:
31.08.2015 14:37:50 (4 years ago)
Author:
kjdon
Message:

doing a simplified paging for cross coll searching. We give a maxdocs arg, and this many docs are returned per collection. Then the results are merged.

Files:
1 modified

Legend:

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

    r28966 r30150  
    4646    protected static final String QUERY_PARAM = "query"; 
    4747    protected static final String COLLECTION_PARAM = "collection"; 
    48  
     48  protected static final String MAXDOCS_PARAM = "maxDocs"; // matches standard maxDocs, but in this case, means max docs per collection 
     49  protected static final String HITS_PER_PAGE_PARAM = "hitsPerPage"; 
     50  protected static final String MAXDOCS_DEFAULT = "20"; 
    4951    // the services on offer - these proxy the actual collection ones 
    5052    protected static final String TEXT_QUERY_SERVICE = "TextQuery"; 
     
    8890        { 
    8991            // add in a default format statement 
    90             String format_string = "<format xmlns:gsf='" + GSXML.GSF_NAMESPACE + "' xmlns:xsl='" + GSXML.XSL_NAMESPACE + "'><gsf:template match='documentNode'><td><a><xsl:attribute name='href'>?a=d&amp;c=<xsl:value-of select='@collection'/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test=\"@nodeType='leaf'\">&amp;sib=1</xsl:if>&amp;dt=<xsl:value-of select='@docType'/>&amp;p.a=q&amp;p.s=" + TEXT_QUERY_SERVICE + "&amp;p.c="; 
     92            String format_string = "<format xmlns:gsf='" + GSXML.GSF_NAMESPACE + "' xmlns:xsl='" + GSXML.XSL_NAMESPACE + "'><gsf:template match='documentNode'><td>poos<a><xsl:attribute name='href'>?a=d&amp;c=<xsl:value-of select='@collection'/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test=\"@nodeType='leaf'\">&amp;sib=1</xsl:if>&amp;dt=<xsl:value-of select='@docType'/>&amp;p.a=q&amp;p.s=" + TEXT_QUERY_SERVICE + "&amp;p.c="; 
    9193            if (this.cluster_name != null) 
    9294            { 
     
    130132                Element param = GSXML.createParameterDescription(doc, COLLECTION_PARAM, getTextString("param." + COLLECTION_PARAM, lang), GSXML.PARAM_TYPE_ENUM_MULTI, "all", coll_ids_list, coll_names_map.get(lang)); 
    131133                param_list.appendChild(param); 
     134                // max docs param 
     135                param = GSXML.createParameterDescription(doc, MAXDOCS_PARAM, getTextString("param." + MAXDOCS_PARAM, lang), GSXML.PARAM_TYPE_INTEGER, MAXDOCS_DEFAULT, null, null); 
     136                param_list.appendChild(param); 
    132137                // query param 
    133138                param = GSXML.createParameterDescription(doc, QUERY_PARAM, getTextString("param." + QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null); 
     
    176181            } 
    177182        } 
    178  
     183         
     184        String maxdocs = MAXDOCS_DEFAULT; 
     185        Element maxdocs_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, MAXDOCS_PARAM); 
     186        if (maxdocs_param != null) { 
     187          maxdocs = GSXML.getValue(maxdocs_param); 
     188        } 
     189         
    179190        Document msg_doc = XMLConverter.newDOM(); 
    180191        Element query_message = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     
    198209        query_request.appendChild(new_param_list); 
    199210        new_param_list.appendChild(msg_doc.importNode(GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, QUERY_PARAM), true)); 
     211 
     212        // for cross coll search, we only want maxdocs from each collection 
     213        // some colls use maxdocs, some use hits per page so lets send both 
     214        new_param_list.appendChild(GSXML.createParameter(msg_doc, MAXDOCS_PARAM, maxdocs)); 
     215        new_param_list.appendChild(GSXML.createParameter(msg_doc, HITS_PER_PAGE_PARAM, maxdocs)); 
    200216        Element query_result = (Element) this.router.process(query_message); 
    201217 
    202         // gather up the data from each response 
    203         int numDocsMatched = 0; 
    204         int numDocsReturned = 0; 
    205  
    206         //term info?? 
    207  
    208         NodeList metadata = query_result.getElementsByTagName(GSXML.METADATA_ELEM); 
    209         for (int j = 0; j < metadata.getLength(); j++) 
    210         { 
    211             Element meta = (Element) metadata.item(j); 
    212             if (meta.getAttribute(GSXML.NAME_ATT).equals("numDocsReturned")) 
    213             { 
    214                 numDocsReturned += Integer.parseInt(GSXML.getValue(meta)); 
    215             } 
    216             else if (meta.getAttribute(GSXML.NAME_ATT).equals("numDocsMatched")) 
    217             { 
    218                 numDocsMatched += Integer.parseInt(GSXML.getValue(meta)); 
    219             } 
    220         } 
    221  
    222         Element metadata_list = result_doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 
    223         result.appendChild(metadata_list); 
    224         GSXML.addMetadata(metadata_list, "numDocsReturned", "" + numDocsReturned); 
    225         //GSXML.addMetadata(metadata_list, "numDocsMatched", ""+numDocsMatched); 
    226  
     218        // create the doc list for the response 
    227219        Element doc_node_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 
    228220        result.appendChild(doc_node_list); 
    229221 
    230222        NodeList responses = query_result.getElementsByTagName(GSXML.RESPONSE_ELEM); 
    231  
     223        int num_docs = 0; 
    232224        for (int k = 0; k < responses.getLength(); k++) 
    233225        { 
     
    236228            if (nodes == null || nodes.getLength() == 0) 
    237229                continue; 
     230            num_docs += nodes.getLength(); 
    238231            Element last_node = null; 
    239232            Element this_node = null; 
     
    258251            } 
    259252        } 
     253        // just send back num docs returned. Too hard to work out number of matches etc as each index type 
     254        // does it differently 
     255        GSXML.addMetadata(metadata_list, "numDocsReturned", "" + num_docs); 
    260256        return result; 
    261257    }