Ignore:
Timestamp:
2016-12-08T02:02:55+13:00 (7 years ago)
Author:
Georgiy Litvinov
Message:

Added java code to use groups in cross collection search

File:
1 edited

Legend:

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

    r30958 r31181  
    4848    protected static final String QUERY_PARAM = "query";
    4949    protected static final String COLLECTION_PARAM = "collection";
     50    protected static final String GROUP_PARAM = "group";
    5051  protected static final String MAXDOCS_PARAM = "maxDocs"; // matches standard maxDocs, but in this case, means max docs per collection
    5152  protected static final String HITS_PER_PAGE_PARAM = "hitsPerPage";
     
    172173            return result; // Return the empty result
    173174        }
    174 
    175175        // get the collection list
    176176        String[] colls_list = coll_ids_list_no_all;
     
    184184            }
    185185        }
     186           
     187        colls_list = mergeGroups(userContext, param_list, colls_list);
    186188       
    187189        String maxdocs = MAXDOCS_DEFAULT;
     
    266268
    267269    //     }
     270   
     271   
     272   
    268273    protected boolean initCollectionList(String lang)
    269274    {
     
    489494        return result;
    490495    }
     496   
     497    private String[] mergeGroups(UserContext userContext, Element paramList, String[] collArray){
     498        Document doc = XMLConverter.newDOM();
     499        Element groupParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GROUP_PARAM);
     500        Element collParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COLLECTION_PARAM);
     501        //Group param not null and coll param null or not 'all'
     502        if (groupParam != null && (collParam == null || !GSXML.getValue(collParam).equals("all")))
     503        {   
     504            //GroupInfo service to get uniq collections
     505            String uniqCollServiceName = "UniqueCollections";
     506            Element infoResponse = getMRInfo(userContext);
     507            Element serviceList = (Element) GSXML.getChildByTagName(infoResponse, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     508            if (serviceList == null) {
     509                logger.error("Service list is null!");
     510                return collArray;
     511            }
     512            Element groupInfoService = GSXML.getNamedElement(serviceList, GSXML.SERVICE_ELEM, GSXML.NAME_ATT,   uniqCollServiceName);
     513            if (groupInfoService == null){
     514                logger.error("UniqueCollections service unavailable; Check your groupConfig.xml");
     515                return collArray;
     516            }
     517            Element groupQueryMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     518            Element groupQueryRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, uniqCollServiceName, userContext);
     519            groupQueryMessage.appendChild(groupQueryRequest);
     520            Element groupParamList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     521            groupQueryRequest.appendChild(groupParamList);
     522            if (collParam != null){
     523                groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM), true));   
     524            }
     525            groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM), true));
     526            Element groupQueryResult = (Element) this.router.process(groupQueryMessage);
     527            Element groupQueryResonse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
     528            Element collList = (Element) GSXML.getChildByTagName(groupQueryResonse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     529            NodeList collections = GSXML.getChildrenByTagName(collList, GSXML.COLLECTION_ELEM);
     530            collArray = new String[collections.getLength()];
     531            for (int i = 0; i < collections.getLength(); i++){
     532                String collName = ((Element) collections.item(i)).getAttribute(GSXML.NAME_ATT);
     533                collArray[i] = collName;
     534            }
     535            return collArray;
     536        }
     537        return collArray;
     538       
     539    }
     540    private Element getMRInfo(UserContext userContext){
     541        Document doc = XMLConverter.newDOM();
     542        Element infoMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     543        Element infoRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);
     544        Element paramList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     545        infoRequest.appendChild(paramList);
     546        GSXML.addParameterToList(paramList, GSXML.SUBSET_PARAM, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     547        infoMessage.appendChild(infoRequest);
     548        Element responseMessage = (Element) this.router.process(infoMessage);
     549        if (responseMessage == null)
     550        {
     551            logger.error("couldn't query the message router!");
     552            return null;
     553        }
     554        Element infoResponse = (Element) GSXML.getChildByTagName(responseMessage, GSXML.RESPONSE_ELEM);
     555        if (infoResponse == null)
     556        {
     557            logger.error("response from message router is null!");
     558            return null;
     559        }
     560       
     561        return infoResponse;
     562       
     563    }
     564   
    491565}
Note: See TracChangeset for help on using the changeset viewer.